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>
This commit is contained in:
David Engraf 2019-01-03 15:28:31 -08:00 committed by Linus Torvalds
parent b058809bfc
commit ff1522bb7d
1 changed files with 3 additions and 3 deletions

View File

@ -550,7 +550,6 @@ static void __init free_initrd(void)
initrd_end = 0;
}
#ifdef CONFIG_BLK_DEV_RAM
#define BUF_SIZE 1024
static void __init clean_rootfs(void)
{
@ -597,7 +596,6 @@ static void __init clean_rootfs(void)
ksys_close(fd);
kfree(buf);
}
#endif
static int __init populate_rootfs(void)
{
@ -640,8 +638,10 @@ static int __init populate_rootfs(void)
printk(KERN_INFO "Unpacking initramfs...\n");
err = unpack_to_rootfs((char *)initrd_start,
initrd_end - initrd_start);
if (err)
if (err) {
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
clean_rootfs();
}
free_initrd();
#endif
}