Skip to content

Commit 26a9242

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/x86: Remove __efistub_global and add relocation check
Instead of using __efistub_global to force variables into the .data section, leave them in the .bss but pull the EFI stub's .bss section into .data in the linker script for the compressed kernel. Add relocation checking for x86 as well to catch non-PC-relative relocations that require runtime processing, since the EFI stub does not do any runtime relocation processing. This will catch, for example, data relocations created by static initializers of pointers. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 420b6d0 commit 26a9242

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SECTIONS
5252
_data = . ;
5353
*(.data)
5454
*(.data.*)
55+
*(.bss.efistub)
5556
_edata = . ;
5657
}
5758
. = ALIGN(L1_CACHE_BYTES);

drivers/firmware/efi/libstub/Makefile

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ lib-$(CONFIG_X86) += x86-stub.o
6060
CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
6161
CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
6262

63+
#
64+
# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the
65+
# .bss section, so the .bss section of the EFI stub needs to be included in the
66+
# .data section of the compressed kernel to ensure initialization. Rename the
67+
# .bss section here so it's easy to pick out in the linker script.
68+
#
69+
STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc
70+
STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32
71+
STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64
72+
73+
#
74+
# ARM discards the .data section because it disallows r/w data in the
75+
# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
76+
# which are preserved explicitly by the decompressor linker script.
77+
#
78+
STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
79+
--rename-section .bss=.bss.efistub,load,alloc
80+
STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS
81+
6382
#
6483
# arm64 puts the stub in the kernel proper, which will unnecessarily retain all
6584
# code indefinitely unless it is annotated as __init/__initdata/__initconst etc.
@@ -74,8 +93,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
7493
# a verification pass to see if any absolute relocations exist in any of the
7594
# object files.
7695
#
77-
extra-$(CONFIG_EFI_GENERIC_STUB) := $(lib-y)
78-
lib-$(CONFIG_EFI_GENERIC_STUB) := $(patsubst %.o,%.stub.o,$(lib-y))
96+
extra-y := $(lib-y)
97+
lib-y := $(patsubst %.o,%.stub.o,$(lib-y))
7998

8099
STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \
81100
--prefix-symbols=__efistub_
@@ -98,12 +117,3 @@ quiet_cmd_stubcopy = STUBCPY $@
98117
/bin/false; \
99118
fi; \
100119
$(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
101-
102-
#
103-
# ARM discards the .data section because it disallows r/w data in the
104-
# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
105-
# which are preserved explicitly by the decompressor linker script.
106-
#
107-
STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
108-
--rename-section .bss=.bss.efistub,load,alloc
109-
STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS

drivers/firmware/efi/libstub/efistub.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
2626
#endif
2727

28-
#if defined(CONFIG_X86)
29-
#define __efistub_global __section(.data)
30-
#else
3128
#define __efistub_global
32-
#endif
3329

3430
extern bool __pure nochunk(void);
3531
extern bool __pure nokaslr(void);

0 commit comments

Comments
 (0)