Skip to content

Commit 538bc0f

Browse files
committed
efi/zboot: Set forward edge CFI compat header flag if supported
Add some plumbing to the zboot EFI header generation to set the newly introduced DllCharacteristicsEx flag associated with forward edge CFI enforcement instructions (BTI on arm64, IBT on x86) x86 does not currently uses the zboot infrastructure, so let's wire it up only for arm64. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent bca2f3a commit 538bc0f

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

arch/arm64/boot/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ $(obj)/Image.zst: $(obj)/Image FORCE
4242
EFI_ZBOOT_PAYLOAD := Image
4343
EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64
4444
EFI_ZBOOT_MACH_TYPE := ARM64
45+
EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL)
4546

4647
include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot

drivers/firmware/efi/libstub/Makefile.zboot

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
# to be include'd by arch/$(ARCH)/boot/Makefile after setting
4-
# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET and EFI_ZBOOT_MACH_TYPE
4+
# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET, EFI_ZBOOT_MACH_TYPE and
5+
# EFI_ZBOOT_FORWARD_CFI
56

67
quiet_cmd_copy_and_pad = PAD $@
78
cmd_copy_and_pad = cp $< $@ && \
@@ -44,10 +45,14 @@ OBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) \
4445
$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE
4546
$(call if_changed,objcopy)
4647

48+
aflags-zboot-header-$(EFI_ZBOOT_FORWARD_CFI) := \
49+
-DPE_DLL_CHAR_EX=IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT
50+
4751
AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \
4852
-DZBOOT_EFI_PATH="\"$(realpath $(obj)/vmlinuz.efi.elf)\"" \
4953
-DZBOOT_SIZE_LEN=$(zboot-size-len-y) \
50-
-DCOMP_TYPE="\"$(comp-type-y)\""
54+
-DCOMP_TYPE="\"$(comp-type-y)\"" \
55+
$(aflags-zboot-header-y)
5156

5257
$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE
5358
$(call if_changed_rule,as_o_S)

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,36 @@ __efistub_efi_zboot_header:
7878
.quad 0 // ExceptionTable
7979
.quad 0 // CertificationTable
8080
.quad 0 // BaseRelocationTable
81-
#ifdef CONFIG_DEBUG_EFI
81+
#if defined(PE_DLL_CHAR_EX) || defined(CONFIG_DEBUG_EFI)
8282
.long .Lefi_debug_table - .Ldoshdr // DebugTable
8383
.long .Lefi_debug_table_size
84+
85+
.section ".rodata", "a"
86+
.p2align 2
87+
.Lefi_debug_table:
88+
// EFI_IMAGE_DEBUG_DIRECTORY_ENTRY[]
89+
#ifdef PE_DLL_CHAR_EX
90+
.long 0 // Characteristics
91+
.long 0 // TimeDateStamp
92+
.short 0 // MajorVersion
93+
.short 0 // MinorVersion
94+
.long IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS // Type
95+
.long 4 // SizeOfData
96+
.long 0 // RVA
97+
.long .Lefi_dll_characteristics_ex - .Ldoshdr // FileOffset
98+
#endif
99+
#ifdef CONFIG_DEBUG_EFI
100+
.long 0 // Characteristics
101+
.long 0 // TimeDateStamp
102+
.short 0 // MajorVersion
103+
.short 0 // MinorVersion
104+
.long IMAGE_DEBUG_TYPE_CODEVIEW // Type
105+
.long .Lefi_debug_entry_size // SizeOfData
106+
.long 0 // RVA
107+
.long .Lefi_debug_entry - .Ldoshdr // FileOffset
108+
#endif
109+
.set .Lefi_debug_table_size, . - .Lefi_debug_table
110+
.previous
84111
#endif
85112

86113
.Lsection_table:
@@ -110,23 +137,11 @@ __efistub_efi_zboot_header:
110137

111138
.set .Lsection_count, (. - .Lsection_table) / 40
112139

140+
#ifdef PE_DLL_CHAR_EX
141+
.Lefi_dll_characteristics_ex:
142+
.long PE_DLL_CHAR_EX
143+
#endif
113144
#ifdef CONFIG_DEBUG_EFI
114-
.section ".rodata", "a"
115-
.align 2
116-
.Lefi_debug_table:
117-
// EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
118-
.long 0 // Characteristics
119-
.long 0 // TimeDateStamp
120-
.short 0 // MajorVersion
121-
.short 0 // MinorVersion
122-
.long IMAGE_DEBUG_TYPE_CODEVIEW // Type
123-
.long .Lefi_debug_entry_size // SizeOfData
124-
.long 0 // RVA
125-
.long .Lefi_debug_entry - .Ldoshdr // FileOffset
126-
127-
.set .Lefi_debug_table_size, . - .Lefi_debug_table
128-
.previous
129-
130145
.Lefi_debug_entry:
131146
// EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
132147
.ascii "NB10" // Signature

0 commit comments

Comments
 (0)