initramfs: Don't free a non-existent initrd
PATCH 1/1 initramfs: Don't free a non-existent initrd
Since 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.
--- init/initramfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
init/initramfs.c +1 -1
@@ -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 ;
Signature · 1 line
2.20.1
Quoted 6 lines · Steven Price
Since
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 ifCONFIG_DEBUG_VIRTUALis enabled due to a call tovirt_to_phys()with a NULL address.
Quoted 8 lines
Instead we should check that the initrd actually exists and only attempt to free it if it does.
Fixes 54c7a8916a88 ("initramfs: free initrd memory if opening /initrd.image fails")Reported-by Mark Rutland <[email protected]>Tested-by Mark Rutland <[email protected]>Signed-off-by Steven Price <[email protected]>---
Quoted 19 lines
init/initramfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)init/initramfs.c +1
-1@@ -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 ;Signature · 1 line
2.20.1
Signature · 2 lines
Sincerely yours, Mike.