From 98d726f8a5d8b6cc272d0c8f6d3995ca98f37d18 Mon Sep 17 00:00:00 2001 From: Steven Price Date: Fri, 17 May 2019 14:31:47 -0700 Subject: initramfs: don't free a non-existent initrd commit 5d59aa8f9ce972b472201aed86e904bb75879ff0 upstream. Since commit 54c7a8916a88 ("initramfs: free initrd memory if opening /initrd.image fails"), the kernel has unconditionally attempted to free the initrd even if it doesn't exist. In the non-existent case this causes a boot-time splat if CONFIG_DEBUG_VIRTUAL is enabled due to a call to virt_to_phys() with a NULL address. Instead we should check that the initrd actually exists and only attempt to free it if it does. Link: http://lkml.kernel.org/r/20190516143125.48948-1-steven.price@arm.com Fixes: 54c7a8916a88 ("initramfs: free initrd memory if opening /initrd.image fails") Signed-off-by: Steven Price Reported-by: Mark Rutland Tested-by: Mark Rutland Reviewed-by: Mike Rapoport Cc: Christoph Hellwig Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [PG: adapt for older 4.18.x codebase with kexec if/else chunk.] Signed-off-by: Paul Gortmaker --- init/initramfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index d638443e12ac..3af2101d19b2 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -542,7 +542,7 @@ static void __init free_initrd(void) * If the initrd region is overlapped with crashkernel reserved region, * free only memory that is not part of crashkernel region. */ - if (initrd_start < crashk_end && initrd_end > crashk_start) { + if (initrd_start && initrd_start < crashk_end && initrd_end > crashk_start) { /* * Initialize initrd memory region since the kexec boot does * not do. @@ -552,7 +552,7 @@ static void __init free_initrd(void) free_initrd_mem(initrd_start, crashk_start); if (initrd_end > crashk_end) free_initrd_mem(crashk_end, initrd_end); - } else + } else if (initrd_start) #endif free_initrd_mem(initrd_start, initrd_end); skip: -- cgit v1.2.2-1-g5e49