Re: [PATCH v2 2/3] powerpc/kexec_file: Fix null-ptr-def in extra size calculation

From
Sourabh Jain <sourabhjain@linux.ibm.com>
Date
2026-07-29 04:01:52
Also in
lkml
Reply to
Jinjie Ruan, 2026-07-29

On 29/07/26 06:59, Jinjie Ruan wrote:
A static Sashiko AI review identified a potential NULL pointer
dereference in kexec_extra_fdt_size_ppc64().

On platforms without any reserved memory regions,
get_reserved_memory_ranges() can return 0 while leaving 'rmem'
unallocated as NULL. Passing it directly leads to a kernel panic when
evaluating 'rmem->nr_ranges'.
Yes that is possible, so it is worth adding NULL check for rmem.
Feel free to add:
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
quoted hunk ↗ jump to hunk
Add a NULL check for 'rmem' to prevent this crash.

Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: <redacted>
Fixes: 0d3ff067331e ("powerpc/kexec_file: fix extra size calculation for kexec FDT")
Signed-off-by: Jinjie Ruan <redacted>
---
  arch/powerpc/kexec/file_load_64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 8c72e12ea44e..6075b1c88511 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -664,7 +664,7 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image, struct crash_mem *
  		extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();
  
  	/* Consider extra space for reserved memory ranges if any */
-	if (rmem->nr_ranges > 0)
+	if (rmem && rmem->nr_ranges > 0)
  		extra_size += sizeof(struct fdt_reserve_entry) * rmem->nr_ranges;
  
  	return extra_size + kdump_extra_fdt_size_ppc64(image, cpu_nodes);
  
Thread (11 messages) 11 messages, 3 authors, last reply 2026-08-03
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help