Skip to contentSkip to conversation

x86/boot: Work around broken busybox truncate tool

PATCH Applied Ard Biesheuvel 6 participants 7 messages Apr 24, 2025 – Apr 30, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot: Work around broken busybox truncate tool

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a % prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used to pad the setup block of bzImage to a multiple of 4k before appending the decompressor.

busybux reimplements truncate but does not support this idiom, and therefore fails the build since commit

9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Work around this by avoiding truncate altogether, and relying on dd to perform the padding.

---
I personally think using a busybox environment for building the kernel is a terrible idea, and does not satisfy the build tool requirements listed in the documentation. But apparently, it used to work and now it doesn't, and the workaround is rather straight-forward.

IOW, I don't care whether this gets applied or not, so I will leave it to others to make the argument.

 arch/x86/boot/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/Makefile +1 -1
index 81f55da81967..640fcac3af74 100644
@@ -59,7 +59,7 @@ KBUILD_CFLAGS	+= $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
 $(obj)/bzImage: asflags-y  := $(SVGA_MODE)
 
 quiet_cmd_image = BUILD   $@
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@
 
 $(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin FORCE
 	$(call if_changed,image)
Signature · 1 line
2.49.0.805.g082f7c87e0-goog
Tested-by on v1 1/1
#1 lore raw

Thank you very much for this fix :)

Quoted 11 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a
% prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used
to pad the setup block of bzImage to a multiple of 4k before appending
the decompressor.

Quoted 1 line

busybux reimplements truncate but does not support this idiom, and

typo, busybox.

Quoted 4 lines

therefore fails the build since commit

  9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Should this be marked as an official bug?

If so, I'd put this as a Fixes: tag below.

Quoted 6 lines

Work around this by avoiding truncate altogether, and relying on dd to
perform the padding.

Thx,

P.

Quoted 31 lines

---
I personally think using a busybox environment for building the kernel
is a terrible idea, and does not satisfy the build tool requirements listed in the documentation. But apparently, it used to work and now it
doesn't, and the workaround is rather straight-forward.

IOW, I don't care whether this gets applied or not, so I will leave it
to others to make the argument.

 arch/x86/boot/Makefile | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/Makefile +0 -0
index 81f55da81967..640fcac3af74 100644
@@ -59,7 +59,7 @@ KBUILD_CFLAGS	+= $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
  $(obj)/bzImage: asflags-y  := $(SVGA_MODE)


 quiet_cmd_image = BUILD   $@
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@

 $(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin FORCE $(call if_changed,image)

#2 lore raw
Quoted 14 lines · Philipp Stanner

Thank you very much for this fix :)

Quoted 11 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a
% prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used
to pad the setup block of bzImage to a multiple of 4k before appending
the decompressor.

Quoted 3 lines
Quoted 1 line

busybux reimplements truncate but does not support this idiom, and

typo, busybox.

Fixed, thx.

Quoted 9 lines
Quoted 5 lines

therefore fails the build since commit

  9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Should this be marked as an official bug?

If so, I'd put this as a Fixes: tag below.

So I've added a Fixes tag, because it's informative, but 9c54baab4401 is new in v6.15-rc1 so there's no backporting need.

Quoted 7 lines
Quoted 5 lines

Work around this by avoiding truncate altogether, and relying on dd to
perform the padding.

Thanks!

Ingo

#3 lore raw
In reply to Ard Biesheuvel
Quoted 28 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a % prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used to pad the setup block of bzImage to a multiple of 4k before appending the decompressor.

busybux reimplements truncate but does not support this idiom, and therefore fails the build since commit

9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Work around this by avoiding truncate altogether, and relying on dd to perform the padding.

---
I personally think using a busybox environment for building the kernel is a terrible idea, and does not satisfy the build tool requirements listed in the documentation. But apparently, it used to work and now it doesn't, and the workaround is rather straight-forward.

IOW, I don't care whether this gets applied or not, so I will leave it to others to make the argument.

quiet_cmd_image = BUILD $@

arch/x86/boot/Makefile KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH) · line 62

Quoted 2 lines
arch/x86/boot/Makefile +1 -1
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@

So the workaround isn't too terrible, and since someone did trigger the bug, debugged it and reported it to us, it costs us very little to apply the workaround and (re-)enable someone's Linux build environment.

Also there's almost no existing usage of 'truncate' within the kernel build system. Found one only:

   drivers/firmware/efi/libstub/Makefile.zboot:			 truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@

Thanks,

Ingo

#4 lore raw
Quoted 31 lines · Ingo Molnar
Quoted 26 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a % prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used to pad the setup block of bzImage to a multiple of 4k before appending the decompressor.

busybux reimplements truncate but does not support this idiom, and therefore fails the build since commit

9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Work around this by avoiding truncate altogether, and relying on dd to perform the padding.

---
I personally think using a busybox environment for building the kernel is a terrible idea, and does not satisfy the build tool requirements listed in the documentation. But apparently, it used to work and now it doesn't, and the workaround is rather straight-forward.

IOW, I don't care whether this gets applied or not, so I will leave it to others to make the argument.

Quoted 8 lines

arch/x86/boot/Makefile KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH) · line 62

Quoted 3 lines

quiet_cmd_image = BUILD $@

arch/x86/boot/Makefile +1 -1
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@

So the workaround isn't too terrible, and since someone did trigger the bug, debugged it and reported it to us, it costs us very little to apply the workaround and (re-)enable someone's Linux build environment.

Indeed.

Quoted 5 lines

Also there's almost no existing usage of 'truncate' within the kernel build system. Found one only:

   drivers/firmware/efi/libstub/Makefile.zboot:                  truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@

Yeah, and it was me who added that one too :-)

merge bot Applied
#6 lore raw

[tip: x86/urgent] x86/boot: Work around broken busybox 'truncate' tool

In reply to Ard Biesheuvel
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     032ce1ea9442e140a80e41078b5431d4c0fa2893
Gitweb:        https://git.kernel.org/tip/032ce1ea9442e140a80e41078b5431d4c0fa2893
Author:        Ard Biesheuvel <[email protected]>
AuthorDate:    Thu, 24 Apr 2025 12:19:18 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 24 Apr 2025 18:23:27 +02:00

x86/boot: Work around broken busybox 'truncate' tool

The GNU coreutils version of truncate, which is the original, accepts a % prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used to pad the setup block of bzImage to a multiple of 4k before appending the decompressor.

busybox reimplements truncate but does not support this idiom, and therefore fails the build since commit

9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Since very little build code within the kernel depends on the 'truncate' utility, work around this incompatibility by avoiding truncate altogether, and relying on dd to perform the padding.

Fixes 9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 arch/x86/boot/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/Makefile +1 -1
index 81f55da..640fcac 100644
@@ -59,7 +59,7 @@ KBUILD_CFLAGS	+= $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
 $(obj)/bzImage: asflags-y  := $(SVGA_MODE)
 
 quiet_cmd_image = BUILD   $@
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@
 
 $(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin FORCE
 	$(call if_changed,image)
#5 lore raw
In reply to Ard Biesheuvel
Quoted 43 lines · On Thu, 24 Apr 2025 18:39:13 +0200 Ard Biesheuvel <[email protected]> wrote:
Quoted 31 lines · Ingo Molnar
Quoted 26 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The GNU coreutils version of truncate, which is the original, accepts a % prefix for the -s size argument which means the file in question should be padded to a multiple of the given size. This is currently used to pad the setup block of bzImage to a multiple of 4k before appending the decompressor.

busybux reimplements truncate but does not support this idiom, and therefore fails the build since commit

9c54baab4401 ("x86/boot: Drop CRC-32 checksum and the build tool that generates it")

Work around this by avoiding truncate altogether, and relying on dd to perform the padding.

---
I personally think using a busybox environment for building the kernel is a terrible idea, and does not satisfy the build tool requirements listed in the documentation. But apparently, it used to work and now it doesn't, and the workaround is rather straight-forward.

IOW, I don't care whether this gets applied or not, so I will leave it to others to make the argument.

Quoted 8 lines

arch/x86/boot/Makefile KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH) · line 62

Quoted 3 lines

quiet_cmd_image = BUILD $@

arch/x86/boot/Makefile +1 -1
-      cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
+      cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@  

So the workaround isn't too terrible, and since someone did trigger the bug, debugged it and reported it to us, it costs us very little to apply the workaround and (re-)enable someone's Linux build environment.

Indeed.

Quoted 7 lines
Quoted 5 lines

Also there's almost no existing usage of 'truncate' within the kernel build system. Found one only:

   drivers/firmware/efi/libstub/Makefile.zboot:                  truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@

Yeah, and it was me who added that one too :-)

That could be changed to use dd as well - since it defaults to truncating the destination at the write offset.

David