Re: [PATCH v2 2/3] powerpc/kexec_file: Fix null-ptr-def in extra size calculation
Sourabh Jain <[email protected]> Wed, 29 Jul 2026 09:31:20 +0530
| Newsgroups | org.ozlabs.lists.linuxppc-dev,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> > > Add a NULL check for 'rmem' to prevent this crash. > > Cc: Sourabh Jain <[email protected]> > Cc: Hari Bathini <[email protected]> > Cc: Michael Ellerman <[email protected]> > Cc: [email protected] > Fixes: 0d3ff067331e ("powerpc/kexec_file: fix extra size calculation for kexec FDT") > Signed-off-by: Jinjie Ruan <[email protected]> > --- > 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);