Skip to content

Commit d20d5a7

Browse files
Randy Robertsontorvalds
authored andcommitted
initramfs: fix initramfs to work with hardlinked init
Change cb6ff20 ("NOMMU: Support XIP on initramfs") seems to have broken booting from initramfs with /sbin/init being a hardlink. It seems like the logic required for XIP on nommu, i.e. ftruncate to reported cpio header file size (body_len) is broken for hardlinks, which have a reported size of 0, and the truncate thus nukes the contents of the file (in my case busybox), making boot impossible and ending with runaway loop modprobe binfmt-0000 - and of course 0000 is not a valid binary format. My fix is to only call ftruncate if size is non-zero which fixes things for me, but I'm not certain whether this will break XIP for those files on nommu systems, although I would guess not. Signed-off-by: Randy Robertson <rmrobert@vmware.com> Acked-by: David Howells <dhowells@redhat.com> Acked-by: Paul Mundt <lethal@linux-sh.org> Acked-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f1671f6 commit d20d5a7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎init/initramfs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ static int __init do_name(void)
310310
if (wfd >= 0) {
311311
sys_fchown(wfd, uid, gid);
312312
sys_fchmod(wfd, mode);
313-
sys_ftruncate(wfd, body_len);
313+
if (body_len)
314+
sys_ftruncate(wfd, body_len);
314315
vcollected = kstrdup(collected, GFP_KERNEL);
315316
state = CopyFile;
316317
}

0 commit comments

Comments
 (0)