Skip to contentSkip to conversation

initramfs: Fix initramfs to work with hardlinked init

PATCH In review Randy Robertson 2 participants 2 messages Apr 6, 2009 – Apr 7, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initramfs: Fix initramfs to work with hardlinked init

Change cb6ff208076b5f434db1b8c983429269d719cef5 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.

This update adds David's ack and fixes whitespace.

---
 init/initramfs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
init/initramfs.c +2 -1
index 80cd713..ddf30d1 100644
@@ -310,7 +310,8 @@ static int __init do_name(void)
 			if (wfd >= 0) {
 				sys_fchown(wfd, uid, gid);
 				sys_fchmod(wfd, mode);
-				sys_ftruncate(wfd, body_len);
+				if (body_len)
+					sys_ftruncate(wfd, body_len);
 				vcollected = kstrdup(collected, GFP_KERNEL);
 				state = CopyFile;
 			}
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Randy Robertson

Change cb6ff208076b5f434db1b8c983429269d719cef5 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.

Quoted 8 lines

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.

This update adds David's ack and fixes whitespace.

Looks right to me.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.