]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
initramfs: don't free a non-existent initrd
authorSteven Price <steven.price@arm.com>
Fri, 17 May 2019 21:31:47 +0000 (14:31 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 16 Oct 2019 09:55:36 +0000 (11:55 +0200)
BugLink: https://bugs.launchpad.net/bugs/1847155
[ Upstream commit 5d59aa8f9ce972b472201aed86e904bb75879ff0 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
init/initramfs.c

index 4be1b65b06763551658c15e773eed96acd1794d8..ffcccf01e77e4fd3d2670e4ad2b6bbc7abaf3462 100644 (file)
@@ -532,7 +532,7 @@ static void __init free_initrd(void)
        unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
        unsigned long crashk_end   = (unsigned long)__va(crashk_res.end);
 #endif
-       if (do_retain_initrd)
+       if (do_retain_initrd || !initrd_start)
                goto skip;
 
 #ifdef CONFIG_KEXEC_CORE