Skip to content

Commit 724b03e

Browse files
committed
Merge tag 'efi-next-for-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI updates from Ard Biesheuvel: "Not a lot going on in the EFI tree this cycle. The only thing that stands out is the new support for SBAT metadata, which was a bit contentious when it was first proposed, because in the initial incarnation, it would have required us to maintain a revocation index, and bump it each time a vulnerability affecting UEFI secure boot got fixed. This was shot down for obvious reasons. This time, only the changes needed to emit the SBAT section into the PE/COFF image are being carried upstream, and it is up to the distros to decide what to put in there when creating and signing the build. This only has the EFI zboot bits (which the distros will be using for arm64); the x86 bzImage changes should be arriving next cycle, presumably via the -tip tree. Summary: - Add support for emitting a .sbat section into the EFI zboot image, so that downstreams can easily include revocation metadata in the signed EFI images - Align PE symbolic constant names with other projects - Bug fix for the efi_test module - Log the physical address and size of the EFI memory map when failing to map it - A kerneldoc fix for the EFI stub code" * tag 'efi-next-for-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: include: pe.h: Fix PE definitions efi/efi_test: Fix missing pending status update in getwakeuptime efi: zboot specific mechanism for embedding SBAT section efi/libstub: Describe missing 'out' parameter in efi_load_initrd efi: Improve logging around memmap init
2 parents 1fbbb62 + 46550e2 commit 724b03e

File tree

15 files changed

+267
-135
lines changed

15 files changed

+267
-135
lines changed

arch/arm/boot/compressed/efi-header.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@ is accepted as an EFI binary. Booting via the UEFI stub
2121
@ will not execute those instructions, but the ARM/Linux
2222
@ boot protocol does, so we need some NOPs here.
23-
.inst MZ_MAGIC | (0xe225 << 16) @ eor r5, r5, 0x4d000
23+
.inst IMAGE_DOS_SIGNATURE | (0xe225 << 16) @ eor r5, r5, 0x4d000
2424
eor r5, r5, 0x4d000 @ undo previous insn
2525
#else
2626
__nop
@@ -43,7 +43,7 @@
4343
.long pe_header - start @ Offset to the PE header.
4444

4545
pe_header:
46-
.long PE_MAGIC
46+
.long IMAGE_NT_SIGNATURE
4747

4848
coff_header:
4949
.short IMAGE_FILE_MACHINE_THUMB @ Machine
@@ -60,7 +60,7 @@ coff_header:
6060
#define __pecoff_code_size (__pecoff_data_start - __efi_start)
6161

6262
optional_header:
63-
.short PE_OPT_MAGIC_PE32 @ PE32 format
63+
.short IMAGE_NT_OPTIONAL_HDR32_MAGIC @ PE32 format
6464
.byte 0x02 @ MajorLinkerVersion
6565
.byte 0x14 @ MinorLinkerVersion
6666
.long __pecoff_code_size @ SizeOfCode

arch/arm64/kernel/efi-header.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
.macro __EFI_PE_HEADER
2929
#ifdef CONFIG_EFI
3030
.set .Lpe_header_offset, . - .L_head
31-
.long PE_MAGIC
31+
.long IMAGE_NT_SIGNATURE
3232
.short IMAGE_FILE_MACHINE_ARM64 // Machine
3333
.short .Lsection_count // NumberOfSections
3434
.long 0 // TimeDateStamp
@@ -40,7 +40,7 @@
4040
IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
4141

4242
.Loptional_header:
43-
.short PE_OPT_MAGIC_PE32PLUS // PE32+ format
43+
.short IMAGE_NT_OPTIONAL_HDR64_MAGIC // PE32+ format
4444
.byte 0x02 // MajorLinkerVersion
4545
.byte 0x14 // MinorLinkerVersion
4646
.long __initdata_begin - .Lefi_header_end // SizeOfCode
@@ -66,7 +66,7 @@
6666
.long .Lefi_header_end - .L_head // SizeOfHeaders
6767
.long 0 // CheckSum
6868
.short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
69-
.short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT // DllCharacteristics
69+
.short IMAGE_DLLCHARACTERISTICS_NX_COMPAT // DllCharacteristics
7070
.quad 0 // SizeOfStackReserve
7171
.quad 0 // SizeOfStackCommit
7272
.quad 0 // SizeOfHeapReserve

arch/loongarch/kernel/efi-header.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/sizes.h>
88

99
.macro __EFI_PE_HEADER
10-
.long PE_MAGIC
10+
.long IMAGE_NT_SIGNATURE
1111
.Lcoff_header:
1212
.short IMAGE_FILE_MACHINE_LOONGARCH64 /* Machine */
1313
.short .Lsection_count /* NumberOfSections */
@@ -20,7 +20,7 @@
2020
IMAGE_FILE_LINE_NUMS_STRIPPED /* Characteristics */
2121

2222
.Loptional_header:
23-
.short PE_OPT_MAGIC_PE32PLUS /* PE32+ format */
23+
.short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
2424
.byte 0x02 /* MajorLinkerVersion */
2525
.byte 0x14 /* MinorLinkerVersion */
2626
.long __inittext_end - .Lefi_header_end /* SizeOfCode */

arch/loongarch/kernel/head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__HEAD
2121

2222
_head:
23-
.word MZ_MAGIC /* "MZ", MS-DOS header */
23+
.word IMAGE_DOS_SIGNATURE /* "MZ", MS-DOS header */
2424
.org 0x8
2525
.dword _kernel_entry /* Kernel entry point (physical address) */
2626
.dword _kernel_asize /* Kernel image effective size */

arch/riscv/kernel/efi-header.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <asm/set_memory.h>
1010

1111
.macro __EFI_PE_HEADER
12-
.long PE_MAGIC
12+
.long IMAGE_NT_SIGNATURE
1313
coff_header:
1414
#ifdef CONFIG_64BIT
1515
.short IMAGE_FILE_MACHINE_RISCV64 // Machine
@@ -27,9 +27,9 @@ coff_header:
2727

2828
optional_header:
2929
#ifdef CONFIG_64BIT
30-
.short PE_OPT_MAGIC_PE32PLUS // PE32+ format
30+
.short IMAGE_NT_OPTIONAL_HDR64_MAGIC // PE32+ format
3131
#else
32-
.short PE_OPT_MAGIC_PE32 // PE32 format
32+
.short IMAGE_NT_OPTIONAL_HDR32_MAGIC // PE32 format
3333
#endif
3434
.byte 0x02 // MajorLinkerVersion
3535
.byte 0x14 // MinorLinkerVersion
@@ -64,7 +64,7 @@ extra_header_fields:
6464
.long efi_header_end - _start // SizeOfHeaders
6565
.long 0 // CheckSum
6666
.short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
67-
.short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT // DllCharacteristics
67+
.short IMAGE_DLLCHARACTERISTICS_NX_COMPAT // DllCharacteristics
6868
.quad 0 // SizeOfStackReserve
6969
.quad 0 // SizeOfStackCommit
7070
.quad 0 // SizeOfHeapReserve

arch/x86/boot/header.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ SYSSEG = 0x1000 /* historical load address >> 4 */
4343
.section ".bstext", "ax"
4444
#ifdef CONFIG_EFI_STUB
4545
# "MZ", MS-DOS header
46-
.word MZ_MAGIC
46+
.word IMAGE_DOS_SIGNATURE
4747
.org 0x38
4848
#
4949
# Offset to the PE header.
5050
#
5151
.long LINUX_PE_MAGIC
5252
.long pe_header
5353
pe_header:
54-
.long PE_MAGIC
54+
.long IMAGE_NT_SIGNATURE
5555

5656
coff_header:
5757
#ifdef CONFIG_X86_32
5858
.set image_file_add_flags, IMAGE_FILE_32BIT_MACHINE
59-
.set pe_opt_magic, PE_OPT_MAGIC_PE32
59+
.set pe_opt_magic, IMAGE_NT_OPTIONAL_HDR32_MAGIC
6060
.word IMAGE_FILE_MACHINE_I386
6161
#else
6262
.set image_file_add_flags, 0
63-
.set pe_opt_magic, PE_OPT_MAGIC_PE32PLUS
63+
.set pe_opt_magic, IMAGE_NT_OPTIONAL_HDR64_MAGIC
6464
.word IMAGE_FILE_MACHINE_AMD64
6565
#endif
6666
.word section_count # nr_sections
@@ -111,7 +111,7 @@ extra_header_fields:
111111
.long salign # SizeOfHeaders
112112
.long 0 # CheckSum
113113
.word IMAGE_SUBSYSTEM_EFI_APPLICATION # Subsystem (EFI application)
114-
.word IMAGE_DLL_CHARACTERISTICS_NX_COMPAT # DllCharacteristics
114+
.word IMAGE_DLLCHARACTERISTICS_NX_COMPAT # DllCharacteristics
115115
#ifdef CONFIG_X86_32
116116
.long 0 # SizeOfStackReserve
117117
.long 0 # SizeOfStackCommit

crypto/asymmetric_keys/verify_pefile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,
4040
} while (0)
4141

4242
chkaddr(0, 0, sizeof(*mz));
43-
if (mz->magic != MZ_MAGIC)
43+
if (mz->magic != IMAGE_DOS_SIGNATURE)
4444
return -ELIBBAD;
4545
cursor = sizeof(*mz);
4646

4747
chkaddr(cursor, mz->peaddr, sizeof(*pe));
4848
pe = pebuf + mz->peaddr;
49-
if (pe->magic != PE_MAGIC)
49+
if (pe->magic != IMAGE_NT_SIGNATURE)
5050
return -ELIBBAD;
5151
cursor = mz->peaddr + sizeof(*pe);
5252

@@ -55,7 +55,7 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,
5555
pe64 = pebuf + cursor;
5656

5757
switch (pe32->magic) {
58-
case PE_OPT_MAGIC_PE32:
58+
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
5959
chkaddr(0, cursor, sizeof(*pe32));
6060
ctx->image_checksum_offset =
6161
(unsigned long)&pe32->csum - (unsigned long)pebuf;
@@ -64,7 +64,7 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,
6464
ctx->n_data_dirents = pe32->data_dirs;
6565
break;
6666

67-
case PE_OPT_MAGIC_PE32PLUS:
67+
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
6868
chkaddr(0, cursor, sizeof(*pe64));
6969
ctx->image_checksum_offset =
7070
(unsigned long)&pe64->csum - (unsigned long)pebuf;

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/efi-stub-helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ efi_status_t efi_load_initrd_cmdline(efi_loaded_image_t *image,
601601
* @image: EFI loaded image protocol
602602
* @soft_limit: preferred address for loading the initrd
603603
* @hard_limit: upper limit address for loading the initrd
604+
* @out: pointer to store the address of the initrd table
604605
*
605606
* Return: status code
606607
*/

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
#ifdef CONFIG_64BIT
66
.set .Lextra_characteristics, 0x0
7-
.set .Lpe_opt_magic, PE_OPT_MAGIC_PE32PLUS
7+
.set .Lpe_opt_magic, IMAGE_NT_OPTIONAL_HDR64_MAGIC
88
#else
99
.set .Lextra_characteristics, IMAGE_FILE_32BIT_MACHINE
10-
.set .Lpe_opt_magic, PE_OPT_MAGIC_PE32
10+
.set .Lpe_opt_magic, IMAGE_NT_OPTIONAL_HDR32_MAGIC
1111
#endif
1212

1313
.section ".head", "a"
1414
.globl __efistub_efi_zboot_header
1515
__efistub_efi_zboot_header:
1616
.Ldoshdr:
17-
.long MZ_MAGIC
17+
.long IMAGE_DOS_SIGNATURE
1818
.ascii "zimg" // image type
1919
.long __efistub__gzdata_start - .Ldoshdr // payload offset
2020
.long __efistub__gzdata_size - ZBOOT_SIZE_LEN // payload size
@@ -25,7 +25,7 @@ __efistub_efi_zboot_header:
2525
.long .Lpehdr - .Ldoshdr // PE header offset
2626

2727
.Lpehdr:
28-
.long PE_MAGIC
28+
.long IMAGE_NT_SIGNATURE
2929
.short MACHINE_TYPE
3030
.short .Lsection_count
3131
.long 0
@@ -63,7 +63,7 @@ __efistub_efi_zboot_header:
6363
.long .Lefi_header_end - .Ldoshdr
6464
.long 0
6565
.short IMAGE_SUBSYSTEM_EFI_APPLICATION
66-
.short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
66+
.short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
6767
#ifdef CONFIG_64BIT
6868
.quad 0, 0, 0, 0
6969
#else
@@ -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));

drivers/firmware/efi/memmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ int __init __efi_memmap_init(struct efi_memory_map_data *data)
4343
map.map = early_memremap(phys_map, data->size);
4444

4545
if (!map.map) {
46-
pr_err("Could not map the memory map!\n");
46+
pr_err("Could not map the memory map! phys_map=%pa, size=0x%lx\n",
47+
&phys_map, data->size);
4748
return -ENOMEM;
4849
}
4950

drivers/firmware/efi/test/efi_test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ static long efi_runtime_get_waketime(unsigned long arg)
361361
getwakeuptime.enabled))
362362
return -EFAULT;
363363

364+
if (getwakeuptime.pending && put_user(pending,
365+
getwakeuptime.pending))
366+
return -EFAULT;
367+
364368
if (getwakeuptime.time) {
365369
if (copy_to_user(getwakeuptime.time, &efi_time,
366370
sizeof(efi_time_t)))

0 commit comments

Comments
 (0)