Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: rename cmd_{bzip2,lzma,lzo,lz4,xzkern,zstd22}

GZIP-compressed files end with 4 byte data that represents the size
of the original input. The decompressors (the self-extracting kernel)
exploit it to know the vmlinux size beforehand. To mimic the GZIP's
trailer, Kbuild provides cmd_{bzip2,lzma,lzo,lz4,xzkern,zstd22}.
Unfortunately these macros are used everywhere despite the appended
size data is only useful for the decompressors.

There is no guarantee that such hand-crafted trailers are safely ignored.
In fact, the kernel refuses compressed initramdfs with the garbage data.
That is why usr/Makefile overrides size_append to make it no-op.

To limit the use of such broken compressed files, this commit renames
the existing macros as follows:

cmd_bzip2 --> cmd_bzip2_with_size
cmd_lzma --> cmd_lzma_with_size
cmd_lzo --> cmd_lzo_with_size
cmd_lz4 --> cmd_lz4_with_size
cmd_xzkern --> cmd_xzkern_with_size
cmd_zstd22 --> cmd_zstd22_with_size

To keep the decompressors working, I updated the following Makefiles
accordingly:

arch/arm/boot/compressed/Makefile
arch/h8300/boot/compressed/Makefile
arch/mips/boot/compressed/Makefile
arch/parisc/boot/compressed/Makefile
arch/s390/boot/compressed/Makefile
arch/sh/boot/compressed/Makefile
arch/x86/boot/compressed/Makefile

I reused the current macro names for the normal usecases; they produce
the compressed data in the proper format.

I did not touch the following:

arch/arc/boot/Makefile
arch/arm64/boot/Makefile
arch/csky/boot/Makefile
arch/mips/boot/Makefile
arch/riscv/boot/Makefile
arch/sh/boot/Makefile
kernel/Makefile

This means those Makefiles will stop appending the size data.

I dropped the 'override size_append' hack from usr/Makefile.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>

+58 -43
+4 -4
arch/arm/boot/compressed/Makefile
··· 77 77 CPPFLAGS_vmlinux.lds += -DMALLOC_SIZE="$(MALLOC_SIZE)" 78 78 79 79 compress-$(CONFIG_KERNEL_GZIP) = gzip 80 - compress-$(CONFIG_KERNEL_LZO) = lzo 81 - compress-$(CONFIG_KERNEL_LZMA) = lzma 82 - compress-$(CONFIG_KERNEL_XZ) = xzkern 83 - compress-$(CONFIG_KERNEL_LZ4) = lz4 80 + compress-$(CONFIG_KERNEL_LZO) = lzo_with_size 81 + compress-$(CONFIG_KERNEL_LZMA) = lzma_with_size 82 + compress-$(CONFIG_KERNEL_XZ) = xzkern_with_size 83 + compress-$(CONFIG_KERNEL_LZ4) = lz4_with_size 84 84 85 85 libfdt_objs := fdt_rw.o fdt_ro.o fdt_wip.o fdt.o 86 86
+3 -1
arch/h8300/boot/compressed/Makefile
··· 30 30 31 31 suffix-$(CONFIG_KERNEL_GZIP) := gzip 32 32 suffix-$(CONFIG_KERNEL_LZO) := lzo 33 + compress-$(CONFIG_KERNEL_GZIP) := gzip 34 + compress-$(CONFIG_KERNEL_LZO) := lzo_with_size 33 35 34 36 $(obj)/vmlinux.bin.$(suffix-y): $(obj)/vmlinux.bin FORCE 35 - $(call if_changed,$(suffix-y)) 37 + $(call if_changed,$(compress-y)) 36 38 37 39 LDFLAGS_piggy.o := -r --format binary --oformat elf32-h8300-linux -T 38 40 OBJCOPYFLAGS := -O binary
+6 -6
arch/mips/boot/compressed/Makefile
··· 64 64 $(call if_changed,objcopy) 65 65 66 66 tool_$(CONFIG_KERNEL_GZIP) = gzip 67 - tool_$(CONFIG_KERNEL_BZIP2) = bzip2 68 - tool_$(CONFIG_KERNEL_LZ4) = lz4 69 - tool_$(CONFIG_KERNEL_LZMA) = lzma 70 - tool_$(CONFIG_KERNEL_LZO) = lzo 71 - tool_$(CONFIG_KERNEL_XZ) = xzkern 72 - tool_$(CONFIG_KERNEL_ZSTD) = zstd22 67 + tool_$(CONFIG_KERNEL_BZIP2) = bzip2_with_size 68 + tool_$(CONFIG_KERNEL_LZ4) = lz4_with_size 69 + tool_$(CONFIG_KERNEL_LZMA) = lzma_with_size 70 + tool_$(CONFIG_KERNEL_LZO) = lzo_with_size 71 + tool_$(CONFIG_KERNEL_XZ) = xzkern_with_size 72 + tool_$(CONFIG_KERNEL_ZSTD) = zstd22_with_size 73 73 74 74 targets += vmlinux.bin.z 75 75
+5 -5
arch/parisc/boot/compressed/Makefile
··· 70 70 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 71 71 $(call if_changed,gzip) 72 72 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 73 - $(call if_changed,bzip2) 73 + $(call if_changed,bzip2_with_size) 74 74 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE 75 - $(call if_changed,lz4) 75 + $(call if_changed,lz4_with_size) 76 76 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 77 - $(call if_changed,lzma) 77 + $(call if_changed,lzma_with_size) 78 78 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 79 - $(call if_changed,lzo) 79 + $(call if_changed,lzo_with_size) 80 80 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 81 - $(call if_changed,xzkern) 81 + $(call if_changed,xzkern_with_size) 82 82 83 83 LDFLAGS_piggy.o := -r --format binary --oformat $(LD_BFD) -T 84 84 $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix-y) FORCE
+6 -6
arch/s390/boot/compressed/Makefile
··· 71 71 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 72 72 $(call if_changed,gzip) 73 73 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 74 - $(call if_changed,bzip2) 74 + $(call if_changed,bzip2_with_size) 75 75 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE 76 - $(call if_changed,lz4) 76 + $(call if_changed,lz4_with_size) 77 77 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 78 - $(call if_changed,lzma) 78 + $(call if_changed,lzma_with_size) 79 79 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 80 - $(call if_changed,lzo) 80 + $(call if_changed,lzo_with_size) 81 81 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 82 - $(call if_changed,xzkern) 82 + $(call if_changed,xzkern_with_size) 83 83 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE 84 - $(call if_changed,zstd22) 84 + $(call if_changed,zstd22_with_size) 85 85 86 86 OBJCOPYFLAGS_piggy.o := -I binary -O elf64-s390 -B s390:64-bit --rename-section .data=.vmlinux.bin.compressed 87 87 $(obj)/piggy.o: $(obj)/vmlinux.bin$(suffix-y) FORCE
+4 -4
arch/sh/boot/compressed/Makefile
··· 52 52 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 53 53 $(call if_changed,gzip) 54 54 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 55 - $(call if_changed,bzip2) 55 + $(call if_changed,bzip2_with_size) 56 56 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 57 - $(call if_changed,lzma) 57 + $(call if_changed,lzma_with_size) 58 58 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 59 - $(call if_changed,xzkern) 59 + $(call if_changed,xzkern_with_size) 60 60 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 61 - $(call if_changed,lzo) 61 + $(call if_changed,lzo_with_size) 62 62 63 63 OBJCOPYFLAGS += -R .empty_zero_page 64 64
+6 -6
arch/x86/boot/compressed/Makefile
··· 123 123 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 124 124 $(call if_changed,gzip) 125 125 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 126 - $(call if_changed,bzip2) 126 + $(call if_changed,bzip2_with_size) 127 127 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 128 - $(call if_changed,lzma) 128 + $(call if_changed,lzma_with_size) 129 129 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 130 - $(call if_changed,xzkern) 130 + $(call if_changed,xzkern_with_size) 131 131 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 132 - $(call if_changed,lzo) 132 + $(call if_changed,lzo_with_size) 133 133 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE 134 - $(call if_changed,lz4) 134 + $(call if_changed,lz4_with_size) 135 135 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE 136 - $(call if_changed,zstd22) 136 + $(call if_changed,zstd22_with_size) 137 137 138 138 suffix-$(CONFIG_KERNEL_GZIP) := gz 139 139 suffix-$(CONFIG_KERNEL_BZIP2) := bz2
+24 -6
scripts/Makefile.lib
··· 395 395 ) 396 396 397 397 quiet_cmd_bzip2 = BZIP2 $@ 398 - cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@ 398 + cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@ 399 + 400 + quiet_cmd_bzip2_with_size = BZIP2 $@ 401 + cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@ 399 402 400 403 # Lzma 401 404 # --------------------------------------------------------------------------- 402 405 403 406 quiet_cmd_lzma = LZMA $@ 404 - cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@ 407 + cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@ 408 + 409 + quiet_cmd_lzma_with_size = LZMA $@ 410 + cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@ 405 411 406 412 quiet_cmd_lzo = LZO $@ 407 - cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@ 413 + cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@ 414 + 415 + quiet_cmd_lzo_with_size = LZO $@ 416 + cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@ 408 417 409 418 quiet_cmd_lz4 = LZ4 $@ 410 - cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \ 419 + cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@ 420 + 421 + quiet_cmd_lz4_with_size = LZ4 $@ 422 + cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \ 411 423 $(size_append); } > $@ 412 424 413 425 # U-Boot mkimage ··· 462 450 # big dictionary would increase the memory usage too much in the multi-call 463 451 # decompression mode. A BCJ filter isn't used either. 464 452 quiet_cmd_xzkern = XZKERN $@ 465 - cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \ 453 + cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@ 454 + 455 + quiet_cmd_xzkern_with_size = XZKERN $@ 456 + cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \ 466 457 $(size_append); } > $@ 467 458 468 459 quiet_cmd_xzmisc = XZMISC $@ ··· 491 476 cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@ 492 477 493 478 quiet_cmd_zstd22 = ZSTD22 $@ 494 - cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ 479 + cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@ 480 + 481 + quiet_cmd_zstd22_with_size = ZSTD22 $@ 482 + cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ 495 483 496 484 # ASM offsets 497 485 # ---------------------------------------------------------------------------
-5
usr/Makefile
··· 3 3 # kbuild file for usr/ - including initramfs image 4 4 # 5 5 6 - # cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the 7 - # size at the end of the compressed file, which unfortunately does not work 8 - # with unpack_to_rootfs(). Make size_append no-op. 9 - override size_append := : 10 - 11 6 compress-y := shipped 12 7 compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip 13 8 compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2