Skip to content

Commit 0f9a173

Browse files
vittyvkardbiesheuvel
authored andcommitted
efi: zboot specific mechanism for embedding SBAT section
SBAT is a mechanism which improves SecureBoot revocations of UEFI binaries by introducing a generation-based technique. Compromised or vulnerable UEFI binaries can be prevented from booting by bumping the minimal required generation for the specific component in the bootloader. More information on the SBAT can be obtained here: https://github.com/rhboot/shim/blob/main/SBAT.md Upstream Linux kernel does not currently participate in any way in SBAT as there's no existing policy in how SBAT generation number should be defined. Keep the status quo and provide a mechanism for distro vendors and anyone else who signs their kernel for SecureBoot to include their own SBAT data. This leaves the decision on the policy to the vendor. Basically, each distro implementing SecureBoot today, will have an option to inject their own SBAT data during kernel build and before it gets signed by their SecureBoot CA. Different distro do not need to agree on the common SBAT component names or generation numbers as each distro ships its own 'shim' with their own 'vendor_cert'/'vendor_db' Implement support for embedding SBAT data for architectures using zboot (arm64, loongarch, riscv). Put '.sbat' section in between '.data' and '.text' as the former also covers '.bss' and thus must be the last one. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 0af2f6b commit 0f9a173

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

drivers/firmware/efi/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,30 @@ config EFI_EMBEDDED_FIRMWARE
281281
bool
282282
select CRYPTO_LIB_SHA256
283283

284+
config EFI_SBAT
285+
def_bool y if EFI_SBAT_FILE!=""
286+
287+
config EFI_SBAT_FILE
288+
string "Embedded SBAT section file path"
289+
depends on EFI_ZBOOT
290+
help
291+
SBAT section provides a way to improve SecureBoot revocations of UEFI
292+
binaries by introducing a generation-based mechanism. With SBAT, older
293+
UEFI binaries can be prevented from booting by bumping the minimal
294+
required generation for the specific component in the bootloader.
295+
296+
Note: SBAT information is distribution specific, i.e. the owner of the
297+
signing SecureBoot certificate must define the SBAT policy. Linux
298+
kernel upstream does not define SBAT components and their generations.
299+
300+
See https://github.com/rhboot/shim/blob/main/SBAT.md for the additional
301+
details.
302+
303+
Specify a file with SBAT data which is going to be embedded as '.sbat'
304+
section into the kernel.
305+
306+
If unsure, leave blank.
307+
284308
endmenu
285309

286310
config UEFI_CPER

drivers/firmware/efi/libstub/Makefile.zboot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE
4444
$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE
4545
$(call if_changed_rule,as_o_S)
4646

47+
ifneq ($(CONFIG_EFI_SBAT_FILE),)
48+
$(obj)/zboot-header.o: $(CONFIG_EFI_SBAT_FILE)
49+
endif
50+
4751
ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a
4852

4953
LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds

drivers/firmware/efi/libstub/zboot-header.S

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,29 @@ __efistub_efi_zboot_header:
123123
IMAGE_SCN_MEM_READ | \
124124
IMAGE_SCN_MEM_EXECUTE
125125

126+
#ifdef CONFIG_EFI_SBAT
127+
.ascii ".sbat\0\0\0"
128+
.long __sbat_size
129+
.long _sbat - .Ldoshdr
130+
.long __sbat_size
131+
.long _sbat - .Ldoshdr
132+
133+
.long 0, 0
134+
.short 0, 0
135+
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
136+
IMAGE_SCN_MEM_READ | \
137+
IMAGE_SCN_MEM_DISCARDABLE
138+
139+
.pushsection ".sbat", "a", @progbits
140+
.incbin CONFIG_EFI_SBAT_FILE
141+
.popsection
142+
#endif
143+
126144
.ascii ".data\0\0\0"
127145
.long __data_size
128-
.long _etext - .Ldoshdr
146+
.long _data - .Ldoshdr
129147
.long __data_rawsize
130-
.long _etext - .Ldoshdr
148+
.long _data - .Ldoshdr
131149

132150
.long 0, 0
133151
.short 0, 0

drivers/firmware/efi/libstub/zboot.lds

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ SECTIONS
2929
. = _etext;
3030
}
3131

32+
#ifdef CONFIG_EFI_SBAT
33+
.sbat : ALIGN(4096) {
34+
_sbat = .;
35+
*(.sbat)
36+
_esbat = ALIGN(4096);
37+
. = _esbat;
38+
}
39+
#endif
40+
3241
.data : ALIGN(4096) {
42+
_data = .;
3343
*(.data* .init.data*)
3444
_edata = ALIGN(512);
3545
. = _edata;
@@ -52,3 +62,4 @@ PROVIDE(__efistub__gzdata_size =
5262

5363
PROVIDE(__data_rawsize = ABSOLUTE(_edata - _etext));
5464
PROVIDE(__data_size = ABSOLUTE(_end - _etext));
65+
PROVIDE(__sbat_size = ABSOLUTE(_esbat - _sbat));

0 commit comments

Comments
 (0)