Skip to content

Commit ff1522b

Browse files
dengraftorvalds
authored andcommitted
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>
1 parent b058809 commit ff1522b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

init/initramfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ static void __init free_initrd(void)
550550
initrd_end = 0;
551551
}
552552

553-
#ifdef CONFIG_BLK_DEV_RAM
554553
#define BUF_SIZE 1024
555554
static void __init clean_rootfs(void)
556555
{
@@ -597,7 +596,6 @@ static void __init clean_rootfs(void)
597596
ksys_close(fd);
598597
kfree(buf);
599598
}
600-
#endif
601599

602600
static int __init populate_rootfs(void)
603601
{
@@ -640,8 +638,10 @@ static int __init populate_rootfs(void)
640638
printk(KERN_INFO "Unpacking initramfs...\n");
641639
err = unpack_to_rootfs((char *)initrd_start,
642640
initrd_end - initrd_start);
643-
if (err)
641+
if (err) {
644642
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
643+
clean_rootfs();
644+
}
645645
free_initrd();
646646
#endif
647647
}

0 commit comments

Comments
 (0)