Skip to content

Commit 61b57d3

Browse files
vittyvkbp3tk0v
authored andcommitted
x86/efi: Implement support for embedding SBAT data for x86
Similar to zboot architectures, implement support for embedding SBAT data for x86. Put '.sbat' section in between '.data' and '.text' as the former also covers '.bss' and '.pgtable' and thus must be the last one in the file. Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent ce2c403 commit 61b57d3

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
7171

7272
SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
7373

74-
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|z_.*\)$$/\#define ZO_\2 0x\1/p'
74+
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|_e\?sbat\|z_.*\)$$/\#define ZO_\2 0x\1/p'
7575

7676
quiet_cmd_zoffset = ZOFFSET $@
7777
cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@

arch/x86/boot/compressed/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o
106106
vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
107107
vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
108108
vmlinux-libs-$(CONFIG_X86_64) += $(objtree)/arch/x86/boot/startup/lib.a
109+
vmlinux-objs-$(CONFIG_EFI_SBAT) += $(obj)/sbat.o
110+
111+
ifdef CONFIG_EFI_SBAT
112+
$(obj)/sbat.o: $(CONFIG_EFI_SBAT_FILE)
113+
endif
109114

110115
$(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE
111116
$(call if_changed,ld)

arch/x86/boot/compressed/sbat.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Embed SBAT data in the kernel.
4+
*/
5+
.pushsection ".sbat", "a", @progbits
6+
.incbin CONFIG_EFI_SBAT_FILE
7+
.popsection

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ SECTIONS
4343
*(.rodata.*)
4444
_erodata = . ;
4545
}
46+
#ifdef CONFIG_EFI_SBAT
47+
.sbat : ALIGN(0x1000) {
48+
_sbat = . ;
49+
*(.sbat)
50+
_esbat = ALIGN(0x1000);
51+
. = _esbat;
52+
}
53+
#endif
4654
.data : ALIGN(0x1000) {
4755
_data = . ;
4856
*(.data)

arch/x86/boot/header.S

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,11 @@ pecompat_fstart:
179179
#else
180180
.set pecompat_fstart, setup_size
181181
#endif
182-
.ascii ".text"
183-
.byte 0
184-
.byte 0
185-
.byte 0
186-
.long ZO__data
187-
.long setup_size
188-
.long ZO__data # Size of initialized data
189-
# on disk
190-
.long setup_size
182+
.ascii ".text\0\0\0"
183+
.long textsize # VirtualSize
184+
.long setup_size # VirtualAddress
185+
.long textsize # SizeOfRawData
186+
.long setup_size # PointerToRawData
191187
.long 0 # PointerToRelocations
192188
.long 0 # PointerToLineNumbers
193189
.word 0 # NumberOfRelocations
@@ -196,6 +192,23 @@ pecompat_fstart:
196192
IMAGE_SCN_MEM_READ | \
197193
IMAGE_SCN_MEM_EXECUTE # Characteristics
198194

195+
#ifdef CONFIG_EFI_SBAT
196+
.ascii ".sbat\0\0\0"
197+
.long ZO__esbat - ZO__sbat # VirtualSize
198+
.long setup_size + ZO__sbat # VirtualAddress
199+
.long ZO__esbat - ZO__sbat # SizeOfRawData
200+
.long setup_size + ZO__sbat # PointerToRawData
201+
202+
.long 0, 0, 0
203+
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
204+
IMAGE_SCN_MEM_READ | \
205+
IMAGE_SCN_MEM_DISCARDABLE # Characteristics
206+
207+
.set textsize, ZO__sbat
208+
#else
209+
.set textsize, ZO__data
210+
#endif
211+
199212
.ascii ".data\0\0\0"
200213
.long ZO__end - ZO__data # VirtualSize
201214
.long setup_size + ZO__data # VirtualAddress

drivers/firmware/efi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ config EFI_SBAT
286286

287287
config EFI_SBAT_FILE
288288
string "Embedded SBAT section file path"
289-
depends on EFI_ZBOOT
289+
depends on EFI_ZBOOT || (EFI_STUB && X86)
290290
help
291291
SBAT section provides a way to improve SecureBoot revocations of UEFI
292292
binaries by introducing a generation-based mechanism. With SBAT, older

0 commit comments

Comments
 (0)