All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] treewide: avoid the ponter addition with NULL pointer
@ 2021-03-23  8:18 sz18665958617
  0 siblings, 0 replies; 4+ messages in thread
From: sz18665958617 @ 2021-03-23  8:18 UTC (permalink / raw)
  To: vgupta; +Cc: linux-snps-arc, dean.yang_cp

From: "dean.yang_cp" <yangdianqing@yulong.com>

Signed-off-by: dean.yang_cp <yangdianqing@yulong.com>
---
 arch/arc/kernel/unwind.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 74ad425..47bab67 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -187,25 +187,26 @@ static void init_unwind_table(struct unwind_table *table, const char *name,
 			      const void *table_start, unsigned long table_size,
 			      const u8 *header_start, unsigned long header_size)
 {
-	const u8 *ptr = header_start + 4;
-	const u8 *end = header_start + header_size;
-
 	table->core.pc = (unsigned long)core_start;
 	table->core.range = core_size;
 	table->init.pc = (unsigned long)init_start;
 	table->init.range = init_size;
 	table->address = table_start;
 	table->size = table_size;
-
-	/* See if the linker provided table looks valid. */
-	if (header_size <= 4
-	    || header_start[0] != 1
-	    || (void *)read_pointer(&ptr, end, header_start[1]) != table_start
-	    || header_start[2] == DW_EH_PE_omit
-	    || read_pointer(&ptr, end, header_start[2]) <= 0
-	    || header_start[3] == DW_EH_PE_omit)
-		header_start = NULL;
-
+	/* To avoid the pointer addition with NULL pointer.*/
+	if (header_start != NULL) {
+		const u8 *ptr = header_start + 4;
+		const u8 *end = header_start + header_size;
+		/* See if the linker provided table looks valid. */
+		if (header_size <= 4
+		|| header_start[0] != 1
+		|| (void *)read_pointer(&ptr, end, header_start[1])
+				!= table_start
+		|| header_start[2] == DW_EH_PE_omit
+		|| read_pointer(&ptr, end, header_start[2]) <= 0
+		|| header_start[3] == DW_EH_PE_omit)
+			header_start = NULL;
+	}
 	table->hdrsz = header_size;
 	smp_wmb();
 	table->header = header_start;
-- 
1.9.1



_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] treewide: avoid the ponter addition with NULL pointer
  2021-02-23  2:00 sz18665958617
@ 2021-02-23  2:42 ` Vineet Gupta
  0 siblings, 0 replies; 4+ messages in thread
From: Vineet Gupta @ 2021-02-23  2:42 UTC (permalink / raw)
  To: sz18665958617; +Cc: dean.yang_cp, linux-snps-arc

On 2/22/21 6:00 PM, sz18665958617@163.com wrote:
> From: "dean.yang_cp" <yangdianqing@yulong.com>
>
> Signed-off-by: dean.yang_cp <yangdianqing@yulong.com>

LGTM.

Acked-by: Vineet Gupta <vgupta@synopsys.com>

Thx,
-Vineet

> ---
>   arch/arc/kernel/unwind.c | 27 ++++++++++++++-------------
>   1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
> index 74ad425..47bab67 100644
> --- a/arch/arc/kernel/unwind.c
> +++ b/arch/arc/kernel/unwind.c
> @@ -187,25 +187,26 @@ static void init_unwind_table(struct unwind_table *table, const char *name,
>   			      const void *table_start, unsigned long table_size,
>   			      const u8 *header_start, unsigned long header_size)
>   {
> -	const u8 *ptr = header_start + 4;
> -	const u8 *end = header_start + header_size;
> -
>   	table->core.pc = (unsigned long)core_start;
>   	table->core.range = core_size;
>   	table->init.pc = (unsigned long)init_start;
>   	table->init.range = init_size;
>   	table->address = table_start;
>   	table->size = table_size;
> -
> -	/* See if the linker provided table looks valid. */
> -	if (header_size <= 4
> -	    || header_start[0] != 1
> -	    || (void *)read_pointer(&ptr, end, header_start[1]) != table_start
> -	    || header_start[2] == DW_EH_PE_omit
> -	    || read_pointer(&ptr, end, header_start[2]) <= 0
> -	    || header_start[3] == DW_EH_PE_omit)
> -		header_start = NULL;
> -
> +	/* To avoid the pointer addition with NULL pointer.*/
> +	if (header_start != NULL) {
> +		const u8 *ptr = header_start + 4;
> +		const u8 *end = header_start + header_size;
> +		/* See if the linker provided table looks valid. */
> +		if (header_size <= 4
> +		|| header_start[0] != 1
> +		|| (void *)read_pointer(&ptr, end, header_start[1])
> +				!= table_start
> +		|| header_start[2] == DW_EH_PE_omit
> +		|| read_pointer(&ptr, end, header_start[2]) <= 0
> +		|| header_start[3] == DW_EH_PE_omit)
> +			header_start = NULL;
> +	}
>   	table->hdrsz = header_size;
>   	smp_wmb();
>   	table->header = header_start;

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] treewide: avoid the ponter addition with NULL pointer
@ 2021-02-23  2:00 sz18665958617
  2021-02-23  2:42 ` Vineet Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: sz18665958617 @ 2021-02-23  2:00 UTC (permalink / raw)
  To: vgupta; +Cc: dean.yang_cp, linux-snps-arc

From: "dean.yang_cp" <yangdianqing@yulong.com>

Signed-off-by: dean.yang_cp <yangdianqing@yulong.com>
---
 arch/arc/kernel/unwind.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 74ad425..47bab67 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -187,25 +187,26 @@ static void init_unwind_table(struct unwind_table *table, const char *name,
 			      const void *table_start, unsigned long table_size,
 			      const u8 *header_start, unsigned long header_size)
 {
-	const u8 *ptr = header_start + 4;
-	const u8 *end = header_start + header_size;
-
 	table->core.pc = (unsigned long)core_start;
 	table->core.range = core_size;
 	table->init.pc = (unsigned long)init_start;
 	table->init.range = init_size;
 	table->address = table_start;
 	table->size = table_size;
-
-	/* See if the linker provided table looks valid. */
-	if (header_size <= 4
-	    || header_start[0] != 1
-	    || (void *)read_pointer(&ptr, end, header_start[1]) != table_start
-	    || header_start[2] == DW_EH_PE_omit
-	    || read_pointer(&ptr, end, header_start[2]) <= 0
-	    || header_start[3] == DW_EH_PE_omit)
-		header_start = NULL;
-
+	/* To avoid the pointer addition with NULL pointer.*/
+	if (header_start != NULL) {
+		const u8 *ptr = header_start + 4;
+		const u8 *end = header_start + header_size;
+		/* See if the linker provided table looks valid. */
+		if (header_size <= 4
+		|| header_start[0] != 1
+		|| (void *)read_pointer(&ptr, end, header_start[1])
+				!= table_start
+		|| header_start[2] == DW_EH_PE_omit
+		|| read_pointer(&ptr, end, header_start[2]) <= 0
+		|| header_start[3] == DW_EH_PE_omit)
+			header_start = NULL;
+	}
 	table->hdrsz = header_size;
 	smp_wmb();
 	table->header = header_start;
-- 
1.9.1



_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] treewide: avoid the ponter addition with NULL pointer
@ 2021-02-07  1:54 sz18665958617
  0 siblings, 0 replies; 4+ messages in thread
From: sz18665958617 @ 2021-02-07  1:54 UTC (permalink / raw)
  To: vgupta; +Cc: dean.yang_cp, linux-snps-arc

From: "dean.yang_cp" <yangdianqing@yulong.com>

Signed-off-by: dean.yang_cp <yangdianqing@yulong.com>
---
 arch/arc/kernel/unwind.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 74ad425..47bab67 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -187,25 +187,26 @@ static void init_unwind_table(struct unwind_table *table, const char *name,
 			      const void *table_start, unsigned long table_size,
 			      const u8 *header_start, unsigned long header_size)
 {
-	const u8 *ptr = header_start + 4;
-	const u8 *end = header_start + header_size;
-
 	table->core.pc = (unsigned long)core_start;
 	table->core.range = core_size;
 	table->init.pc = (unsigned long)init_start;
 	table->init.range = init_size;
 	table->address = table_start;
 	table->size = table_size;
-
-	/* See if the linker provided table looks valid. */
-	if (header_size <= 4
-	    || header_start[0] != 1
-	    || (void *)read_pointer(&ptr, end, header_start[1]) != table_start
-	    || header_start[2] == DW_EH_PE_omit
-	    || read_pointer(&ptr, end, header_start[2]) <= 0
-	    || header_start[3] == DW_EH_PE_omit)
-		header_start = NULL;
-
+	/* To avoid the pointer addition with NULL pointer.*/
+	if (header_start != NULL) {
+		const u8 *ptr = header_start + 4;
+		const u8 *end = header_start + header_size;
+		/* See if the linker provided table looks valid. */
+		if (header_size <= 4
+		|| header_start[0] != 1
+		|| (void *)read_pointer(&ptr, end, header_start[1])
+				!= table_start
+		|| header_start[2] == DW_EH_PE_omit
+		|| read_pointer(&ptr, end, header_start[2]) <= 0
+		|| header_start[3] == DW_EH_PE_omit)
+			header_start = NULL;
+	}
 	table->hdrsz = header_size;
 	smp_wmb();
 	table->header = header_start;
-- 
1.9.1



_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-23  8:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  8:18 [PATCH] treewide: avoid the ponter addition with NULL pointer sz18665958617
  -- strict thread matches above, loose matches on Subject: below --
2021-02-23  2:00 sz18665958617
2021-02-23  2:42 ` Vineet Gupta
2021-02-07  1:54 sz18665958617

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.