Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

initramfs: cleanup incomplete rootfs

Unpacking an external initrd may fail e.g. not enough memory. This
leads to an incomplete rootfs because some files might be extracted
already. Fixed by cleaning the rootfs so the kernel is not using an
incomplete rootfs.

Link: http://lkml.kernel.org/r/20181030151805.5519-1-david.engraf@sysgo.com
Signed-off-by: David Engraf <david.engraf@sysgo.com>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Engraf and committed by
Linus Torvalds
ff1522bb b058809b

+3 -3
+3 -3
init/initramfs.c
··· 550 550 initrd_end = 0; 551 551 } 552 552 553 - #ifdef CONFIG_BLK_DEV_RAM 554 553 #define BUF_SIZE 1024 555 554 static void __init clean_rootfs(void) 556 555 { ··· 596 597 ksys_close(fd); 597 598 kfree(buf); 598 599 } 599 - #endif 600 600 601 601 static int __init populate_rootfs(void) 602 602 { ··· 638 640 printk(KERN_INFO "Unpacking initramfs...\n"); 639 641 err = unpack_to_rootfs((char *)initrd_start, 640 642 initrd_end - initrd_start); 641 - if (err) 643 + if (err) { 642 644 printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); 645 + clean_rootfs(); 646 + } 643 647 free_initrd(); 644 648 #endif 645 649 }