Skip to content

Commit

Permalink
initramfs: don't free a non-existent initrd
Browse files Browse the repository at this point in the history
Since commit 54c7a89 ("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/[email protected]
Fixes: 54c7a89 ("initramfs: free initrd memory if opening /initrd.image fails")
Signed-off-by: Steven Price <[email protected]>
Reported-by: Mark Rutland <[email protected]>
Tested-by: Mark Rutland <[email protected]>
Reviewed-by: Mike Rapoport <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Steven Price authored and torvalds committed May 18, 2019
1 parent ec084de commit 5d59aa8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ static int __init populate_rootfs(void)
* If the initrd region is overlapped with crashkernel reserved region,
* free only memory that is not part of crashkernel region.
*/
if (!do_retain_initrd && !kexec_free_initrd())
if (!do_retain_initrd && initrd_start && !kexec_free_initrd())
free_initrd_mem(initrd_start, initrd_end);
initrd_start = 0;
initrd_end = 0;
Expand Down

0 comments on commit 5d59aa8

Please sign in to comment.