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

kbuild: Split .modinfo out from ELF_DETAILS

Commit 3e86e4d74c04 ("kbuild: keep .modinfo section in
vmlinux.unstripped") added .modinfo to ELF_DETAILS while removing it
from COMMON_DISCARDS, as it was needed in vmlinux.unstripped and
ELF_DETAILS was present in all architecture specific vmlinux linker
scripts. While this shuffle is fine for vmlinux, ELF_DETAILS and
COMMON_DISCARDS may be used by other linker scripts, such as the s390
and x86 compressed boot images, which may not expect to have a .modinfo
section. In certain circumstances, this could result in a bootloader
failing to load the compressed kernel [1].

Commit ddc6cbef3ef1 ("s390/boot/vmlinux.lds.S: Ensure bzImage ends with
SecureBoot trailer") recently addressed this for the s390 bzImage but
the same bug remains for arm, parisc, and x86. The presence of .modinfo
in the x86 bzImage was the root cause of the issue worked around with
commit d50f21091358 ("kbuild: align modinfo section for Secureboot
Authenticode EDK2 compat"). misc.c in arch/x86/boot/compressed includes
lib/decompress_unzstd.c, which in turn includes lib/xxhash.c and its
MODULE_LICENSE / MODULE_DESCRIPTION macros due to the STATIC definition.

Split .modinfo out from ELF_DETAILS into its own macro and handle it in
all vmlinux linker scripts. Discard .modinfo in the places where it was
previously being discarded from being in COMMON_DISCARDS, as it has
never been necessary in those uses.

Cc: stable@vger.kernel.org
Fixes: 3e86e4d74c04 ("kbuild: keep .modinfo section in vmlinux.unstripped")
Reported-by: Ed W <lists@wildgooses.com>
Closes: https://lore.kernel.org/587f25e0-a80e-46a5-9f01-87cb40cfa377@wildgooses.com/ [1]
Tested-by: Ed W <lists@wildgooses.com> # x86_64
Link: https://patch.msgid.link/20260225-separate-modinfo-from-elf-details-v1-1-387ced6baf4b@kernel.org
Signed-off-by: Nathan Chancellor <nathan@kernel.org>

+29 -2
+1
arch/alpha/kernel/vmlinux.lds.S
··· 71 71 72 72 STABS_DEBUG 73 73 DWARF_DEBUG 74 + MODINFO 74 75 ELF_DETAILS 75 76 76 77 DISCARDS
+1
arch/arc/kernel/vmlinux.lds.S
··· 123 123 _end = . ; 124 124 125 125 STABS_DEBUG 126 + MODINFO 126 127 ELF_DETAILS 127 128 DISCARDS 128 129
+1
arch/arm/boot/compressed/vmlinux.lds.S
··· 21 21 COMMON_DISCARDS 22 22 *(.ARM.exidx*) 23 23 *(.ARM.extab*) 24 + *(.modinfo) 24 25 *(.note.*) 25 26 *(.rel.*) 26 27 *(.printk_index)
+1
arch/arm/kernel/vmlinux-xip.lds.S
··· 154 154 155 155 STABS_DEBUG 156 156 DWARF_DEBUG 157 + MODINFO 157 158 ARM_DETAILS 158 159 159 160 ARM_ASSERTS
+1
arch/arm/kernel/vmlinux.lds.S
··· 153 153 154 154 STABS_DEBUG 155 155 DWARF_DEBUG 156 + MODINFO 156 157 ARM_DETAILS 157 158 158 159 ARM_ASSERTS
+1
arch/arm64/kernel/vmlinux.lds.S
··· 349 349 350 350 STABS_DEBUG 351 351 DWARF_DEBUG 352 + MODINFO 352 353 ELF_DETAILS 353 354 354 355 HEAD_SYMBOLS
+1
arch/csky/kernel/vmlinux.lds.S
··· 109 109 110 110 STABS_DEBUG 111 111 DWARF_DEBUG 112 + MODINFO 112 113 ELF_DETAILS 113 114 114 115 DISCARDS
+1
arch/hexagon/kernel/vmlinux.lds.S
··· 62 62 63 63 STABS_DEBUG 64 64 DWARF_DEBUG 65 + MODINFO 65 66 ELF_DETAILS 66 67 .hexagon.attributes 0 : { *(.hexagon.attributes) } 67 68
+1
arch/loongarch/kernel/vmlinux.lds.S
··· 147 147 148 148 STABS_DEBUG 149 149 DWARF_DEBUG 150 + MODINFO 150 151 ELF_DETAILS 151 152 152 153 #ifdef CONFIG_EFI_STUB
+1
arch/m68k/kernel/vmlinux-nommu.lds
··· 85 85 _end = .; 86 86 87 87 STABS_DEBUG 88 + MODINFO 88 89 ELF_DETAILS 89 90 90 91 /* Sections to be discarded */
+1
arch/m68k/kernel/vmlinux-std.lds
··· 58 58 _end = . ; 59 59 60 60 STABS_DEBUG 61 + MODINFO 61 62 ELF_DETAILS 62 63 63 64 /* Sections to be discarded */
+1
arch/m68k/kernel/vmlinux-sun3.lds
··· 51 51 _end = . ; 52 52 53 53 STABS_DEBUG 54 + MODINFO 54 55 ELF_DETAILS 55 56 56 57 /* Sections to be discarded */
+1
arch/mips/kernel/vmlinux.lds.S
··· 217 217 218 218 STABS_DEBUG 219 219 DWARF_DEBUG 220 + MODINFO 220 221 ELF_DETAILS 221 222 222 223 /* These must appear regardless of . */
+1
arch/nios2/kernel/vmlinux.lds.S
··· 57 57 58 58 STABS_DEBUG 59 59 DWARF_DEBUG 60 + MODINFO 60 61 ELF_DETAILS 61 62 62 63 DISCARDS
+1
arch/openrisc/kernel/vmlinux.lds.S
··· 101 101 /* Throw in the debugging sections */ 102 102 STABS_DEBUG 103 103 DWARF_DEBUG 104 + MODINFO 104 105 ELF_DETAILS 105 106 106 107 /* Sections to be discarded -- must be last */
+1
arch/parisc/boot/compressed/vmlinux.lds.S
··· 90 90 /* Sections to be discarded */ 91 91 DISCARDS 92 92 /DISCARD/ : { 93 + *(.modinfo) 93 94 #ifdef CONFIG_64BIT 94 95 /* temporary hack until binutils is fixed to not emit these 95 96 * for static binaries
+1
arch/parisc/kernel/vmlinux.lds.S
··· 165 165 _end = . ; 166 166 167 167 STABS_DEBUG 168 + MODINFO 168 169 ELF_DETAILS 169 170 .note 0 : { *(.note) } 170 171
+1
arch/powerpc/kernel/vmlinux.lds.S
··· 397 397 _end = . ; 398 398 399 399 DWARF_DEBUG 400 + MODINFO 400 401 ELF_DETAILS 401 402 402 403 DISCARDS
+1
arch/riscv/kernel/vmlinux.lds.S
··· 170 170 171 171 STABS_DEBUG 172 172 DWARF_DEBUG 173 + MODINFO 173 174 ELF_DETAILS 174 175 .riscv.attributes 0 : { *(.riscv.attributes) } 175 176
+1
arch/s390/kernel/vmlinux.lds.S
··· 221 221 /* Debugging sections. */ 222 222 STABS_DEBUG 223 223 DWARF_DEBUG 224 + MODINFO 224 225 ELF_DETAILS 225 226 226 227 /*
+1
arch/sh/kernel/vmlinux.lds.S
··· 89 89 90 90 STABS_DEBUG 91 91 DWARF_DEBUG 92 + MODINFO 92 93 ELF_DETAILS 93 94 94 95 DISCARDS
+1
arch/sparc/kernel/vmlinux.lds.S
··· 191 191 192 192 STABS_DEBUG 193 193 DWARF_DEBUG 194 + MODINFO 194 195 ELF_DETAILS 195 196 196 197 DISCARDS
+1
arch/um/kernel/dyn.lds.S
··· 172 172 173 173 STABS_DEBUG 174 174 DWARF_DEBUG 175 + MODINFO 175 176 ELF_DETAILS 176 177 177 178 DISCARDS
+1
arch/um/kernel/uml.lds.S
··· 113 113 114 114 STABS_DEBUG 115 115 DWARF_DEBUG 116 + MODINFO 116 117 ELF_DETAILS 117 118 118 119 DISCARDS
+1 -1
arch/x86/boot/compressed/vmlinux.lds.S
··· 88 88 /DISCARD/ : { 89 89 *(.dynamic) *(.dynsym) *(.dynstr) *(.dynbss) 90 90 *(.hash) *(.gnu.hash) 91 - *(.note.*) 91 + *(.note.*) *(.modinfo) 92 92 } 93 93 94 94 .got.plt (INFO) : {
+1
arch/x86/kernel/vmlinux.lds.S
··· 427 427 .llvm_bb_addr_map : { *(.llvm_bb_addr_map) } 428 428 #endif 429 429 430 + MODINFO 430 431 ELF_DETAILS 431 432 432 433 DISCARDS
+3 -1
include/asm-generic/vmlinux.lds.h
··· 848 848 849 849 /* Required sections not related to debugging. */ 850 850 #define ELF_DETAILS \ 851 - .modinfo : { *(.modinfo) . = ALIGN(8); } \ 852 851 .comment 0 : { *(.comment) } \ 853 852 .symtab 0 : { *(.symtab) } \ 854 853 .strtab 0 : { *(.strtab) } \ 855 854 .shstrtab 0 : { *(.shstrtab) } 855 + 856 + #define MODINFO \ 857 + .modinfo : { *(.modinfo) . = ALIGN(8); } 856 858 857 859 #ifdef CONFIG_GENERIC_BUG 858 860 #define BUG_TABLE \