Commit d20d5a74 authored by Randy Robertson's avatar Randy Robertson Committed by Linus Torvalds

initramfs: fix initramfs to work with hardlinked init

Change cb6ff208 ("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: default avatarRandy Robertson <rmrobert@vmware.com>
Acked-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarPaul Mundt <lethal@linux-sh.org>
Acked-by: default avatarH. Peter Anvin <hpa@zytor.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f1671f6d
...@@ -310,6 +310,7 @@ static int __init do_name(void) ...@@ -310,6 +310,7 @@ static int __init do_name(void)
if (wfd >= 0) { if (wfd >= 0) {
sys_fchown(wfd, uid, gid); sys_fchown(wfd, uid, gid);
sys_fchmod(wfd, mode); sys_fchmod(wfd, mode);
if (body_len)
sys_ftruncate(wfd, body_len); sys_ftruncate(wfd, body_len);
vcollected = kstrdup(collected, GFP_KERNEL); vcollected = kstrdup(collected, GFP_KERNEL);
state = CopyFile; state = CopyFile;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment