Skip to content

Commit 9c54baa

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
x86/boot: Drop CRC-32 checksum and the build tool that generates it
Apart from some sanity checks on the size of setup.bin, the only remaining task carried out by the arch/x86/boot/tools/build.c build tool is generating the CRC-32 checksum of the bzImage. This feature was added in commit 7d6e737 ("x86: add a crc32 checksum to the kernel image.") without any motivation (or any commit log text, for that matter). This checksum is not verified by any known bootloader, and given that a) the checksum of the entire bzImage is reported by most tools (zlib, rhash) as 0xffffffff and not 0x0 as documented, b) the checksum is corrupted when the image is signed for secure boot, which means that no distro ships x86 images with valid CRCs, it seems quite unlikely that this checksum is being used, so let's just drop it, along with the tool that generates it. Instead, use simple file concatenation and truncation to combine the two pieces into bzImage, and replace the checks on the size of the setup block with a couple of ASSERT()s in the linker script. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ian Campbell <ijc@hellion.org.uk> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/20250307164801.885261-2-ardb+git@google.com
1 parent e451630 commit 9c54baa

File tree

6 files changed

+5
-266
lines changed

6 files changed

+5
-266
lines changed

Documentation/arch/x86/boot.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,16 +1038,6 @@ Offset/size: 0x000c/4
10381038
This field contains maximal allowed type for setup_data and setup_indirect structs.
10391039

10401040

1041-
The Image Checksum
1042-
==================
1043-
1044-
From boot protocol version 2.08 onwards the CRC-32 is calculated over
1045-
the entire file using the characteristic polynomial 0x04C11DB7 and an
1046-
initial remainder of 0xffffffff. The checksum is appended to the
1047-
file; therefore the CRC of the file up to the limit specified in the
1048-
syssize field of the header is always 0.
1049-
1050-
10511041
The Kernel Command Line
10521042
=======================
10531043

arch/x86/boot/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ setup-y += video-vesa.o
3535
setup-y += video-bios.o
3636

3737
targets += $(setup-y)
38-
hostprogs := tools/build
3938
hostprogs += mkcpustr
4039

4140
HOST_EXTRACFLAGS += -I$(srctree)/tools/include \
@@ -61,11 +60,9 @@ KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
6160
$(obj)/bzImage: asflags-y := $(SVGA_MODE)
6261

6362
quiet_cmd_image = BUILD $@
64-
silent_redirect_image = >/dev/null
65-
cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin \
66-
$(obj)/zoffset.h $@ $($(quiet)redirect_image)
63+
cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
6764

68-
$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE
65+
$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin FORCE
6966
$(call if_changed,image)
7067
@$(kecho) 'Kernel: $@ is ready' ' (#'$(or $(KBUILD_BUILD_VERSION),`cat .version`)')'
7168

arch/x86/boot/compressed/vmlinux.lds.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ SECTIONS
4848
*(.data)
4949
*(.data.*)
5050

51-
/* Add 4 bytes of extra space for a CRC-32 checksum */
52-
. = ALIGN(. + 4, 0x200);
51+
. = ALIGN(0x200);
5352
_edata = . ;
5453
}
5554
. = ALIGN(L1_CACHE_BYTES);

arch/x86/boot/setup.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ SECTIONS
4545

4646
setup_size = ALIGN(ABSOLUTE(.), 4096);
4747
setup_sects = ABSOLUTE(setup_size / 512);
48+
ASSERT(setup_sects >= 5, "The setup must be at least 5 sectors in size");
49+
ASSERT(setup_sects <= 64, "The setup must be at most 64 sectors in size");
4850
}
4951

5052
. = ALIGN(16);

arch/x86/boot/tools/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

arch/x86/boot/tools/build.c

Lines changed: 0 additions & 247 deletions
This file was deleted.

0 commit comments

Comments
 (0)