Skip to content

Commit

Permalink
x86/boot: Drop CRC-32 checksum and the build tool that generates it
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ard Biesheuvel authored and Ingo Molnar committed Mar 7, 2025
1 parent e451630 commit 9c54baa
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 266 deletions.
10 changes: 0 additions & 10 deletions Documentation/arch/x86/boot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1038,16 +1038,6 @@ Offset/size: 0x000c/4
This field contains maximal allowed type for setup_data and setup_indirect structs.


The Image Checksum
==================

From boot protocol version 2.08 onwards the CRC-32 is calculated over
the entire file using the characteristic polynomial 0x04C11DB7 and an
initial remainder of 0xffffffff. The checksum is appended to the
file; therefore the CRC of the file up to the limit specified in the
syssize field of the header is always 0.


The Kernel Command Line
=======================

Expand Down
7 changes: 2 additions & 5 deletions arch/x86/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ setup-y += video-vesa.o
setup-y += video-bios.o

targets += $(setup-y)
hostprogs := tools/build
hostprogs += mkcpustr

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions arch/x86/boot/compressed/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ SECTIONS
*(.data)
*(.data.*)

/* Add 4 bytes of extra space for a CRC-32 checksum */
. = ALIGN(. + 4, 0x200);
. = ALIGN(0x200);
_edata = . ;
}
. = ALIGN(L1_CACHE_BYTES);
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/boot/setup.ld
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ SECTIONS

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

. = ALIGN(16);
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/boot/tools/.gitignore

This file was deleted.

247 changes: 0 additions & 247 deletions arch/x86/boot/tools/build.c

This file was deleted.

0 comments on commit 9c54baa

Please sign in to comment.