arch/x86/boot/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
From: Ard Biesheuvel <ardb@kernel.org>
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.
Reported-by: <phasta@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
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(-)
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 81f55da81967..640fcac3af74 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -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.49.0.805.g082f7c87e0-goog
* Ard Biesheuvel <ardb+git@google.com> wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> 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.
>
> Reported-by: <phasta@kernel.org>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> 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 $@
> - 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
On Thu, 24 Apr 2025 at 18:29, Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * Ard Biesheuvel <ardb+git@google.com> wrote:
>
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > 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.
> >
> > Reported-by: <phasta@kernel.org>
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> > 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 $@
> > - 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.
> 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 :-)
On Thu, 24 Apr 2025 18:39:13 +0200
Ard Biesheuvel <ardb@kernel.org> wrote:
> On Thu, 24 Apr 2025 at 18:29, Ingo Molnar <mingo@kernel.org> wrote:
> >
> >
> > * Ard Biesheuvel <ardb+git@google.com> wrote:
> >
> > > From: Ard Biesheuvel <ardb@kernel.org>
> > >
> > > 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.
> > >
> > > Reported-by: <phasta@kernel.org>
> > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > > ---
> > > 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 $@
> > > - 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.
>
> > 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
Thank you very much for this fix :)
On Thu, 2025-04-24 at 12:19 +0200, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> 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
typo, busybox.
> 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.
>
> Work around this by avoiding truncate altogether, and relying on dd
> to
> perform the padding.
>
> Reported-by: <phasta@kernel.org>
Tested-by: Philipp Stanner <phasta@kernel.org>
Thx,
P.
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> 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(-)
>
> diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
> index 81f55da81967..640fcac3af74 100644
> --- a/arch/x86/boot/Makefile
> +++ b/arch/x86/boot/Makefile
> @@ -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)
* Philipp Stanner <phasta@mailbox.org> wrote:
> Thank you very much for this fix :)
>
> On Thu, 2025-04-24 at 12:19 +0200, Ard Biesheuvel wrote:
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > 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
>
> typo, busybox.
Fixed, thx.
>
> > 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.
> > Work around this by avoiding truncate altogether, and relying on dd
> > to
> > perform the padding.
> >
> > Reported-by: <phasta@kernel.org>
>
> Tested-by: Philipp Stanner <phasta@kernel.org>
Thanks!
Ingo
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 <ardb@kernel.org>
AuthorDate: Thu, 24 Apr 2025 12:19:18 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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")
Reported-by: <phasta@kernel.org>
Tested-by: Philipp Stanner <phasta@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250424101917.1552527-2-ardb+git@google.com
---
arch/x86/boot/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 81f55da..640fcac 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -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)
© 2016 - 2026 Red Hat, Inc.