aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Price <steven.price@arm.com>2019-05-17 14:31:47 -0700
committerPaul Gortmaker <paul.gortmaker@windriver.com>2019-09-16 12:21:47 -0400
commit98d726f8a5d8b6cc272d0c8f6d3995ca98f37d18 (patch)
treef471dac5f454e6dd0e8beb034f6c23c9ecbf5661
parent499b834757cd3fa3af5d66cc835e3d3baab1d1a7 (diff)
downloadlinux-yocto-98d726f8a5d8b6cc272d0c8f6d3995ca98f37d18.tar.gz
linux-yocto-98d726f8a5d8b6cc272d0c8f6d3995ca98f37d18.tar.bz2
linux-yocto-98d726f8a5d8b6cc272d0c8f6d3995ca98f37d18.zip
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 <steven.price@arm.com> Reported-by: Mark Rutland <mark.rutland@arm.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> [PG: adapt for older 4.18.x codebase with kexec if/else chunk.] Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
-rw-r--r--init/initramfs.c4
1 files 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: