Skip to content

Commit

Permalink
initramfs: cleanup incomplete rootfs
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: David Engraf <[email protected]>
Cc: Dominik Brodowski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Philippe Ombredanne <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Luc Van Oostenryck <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dengraf authored and torvalds committed Jan 4, 2019
1 parent b058809 commit ff1522b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -597,7 +596,6 @@ static void __init clean_rootfs(void)
ksys_close(fd);
kfree(buf);
}
#endif

static int __init populate_rootfs(void)
{
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ff1522b

Please sign in to comment.