History

Merge tag 'efi-next-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi

Pull EFI updates from Ard Biesheuvel: - support taking the measurement of the initrd when loaded via the LoadFile2 protocol - kobject API cleanup from Greg - some header file whitespace fixes * tag 'efi-next-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efi: use default_groups in kobj_type efi/libstub: measure loaded initrd info into the TPM efi/libstub: consolidate initrd handling across architectures efi/libstub: x86/mixed: increase supported argument count efi/libstub: add prototype of efi_tcg2_protocol::hash_log_extend_event() include/linux/efi.h: Remove unneeded whitespaces before tabs

Linus Torvalds committed 4 years ago

Commit f12fc752 parents f692121 42f404611 files · +144 −53Browse files

Unified · Split

11 files
  1. arch/x86/boot/compressed/efi_thunk_64.S +11 −3
  2. arch/x86/include/asm/efi.h +10 −4
  3. arch/x86/platform/efi/efi_thunk_64.S +12 −2
  4. drivers/firmware/efi/efivars.c +2 −1
  5. drivers/firmware/efi/esrt.c +3 −1
  6. drivers/firmware/efi/libstub/efi-stub-helper.c +61 −12
  7. drivers/firmware/efi/libstub/efi-stub.c +2 −8
  8. drivers/firmware/efi/libstub/efistub.h +28 −2
  9. drivers/firmware/efi/libstub/x86-stub.c +10 −16
  10. drivers/firmware/efi/runtime-map.c +2 −1
  11. include/linux/efi.h +3 −3
arch/x86/boot/compressed/efi_thunk_64.S+11−3
@@ -26,8 +26,6 @@ SYM_FUNC_START(__efi64_thunk) · 25 unmodified lines
2626 push %rbp
2727 push %rbx
2828
29− leaq 1f(%rip), %rbp
30−
3129 movl %ds, %eax
3230 push %rax
3331 movl %es, %eax
@@ -35,6 +33,11 @@ SYM_FUNC_START(__efi64_thunk) · 1 unmodified line
3533 movl %ss, %eax
3634 push %rax
3735
36+ /* Copy args passed on stack */
37+ movq 0x30(%rsp), %rbp
38+ movq 0x38(%rsp), %rbx
39+ movq 0x40(%rsp), %rax
40+
3841 /*
3942 * Convert x86-64 ABI params to i386 ABI
4043 */
@@ -44,13 +47,18 @@ SYM_FUNC_START(__efi64_thunk) · 3 unmodified lines
4447 movl %ecx, 0x8(%rsp)
4548 movl %r8d, 0xc(%rsp)
4649 movl %r9d, 0x10(%rsp)
50+ movl %ebp, 0x14(%rsp)
51+ movl %ebx, 0x18(%rsp)
52+ movl %eax, 0x1c(%rsp)
4753
48− leaq 0x14(%rsp), %rbx
54+ leaq 0x20(%rsp), %rbx
4955 sgdt (%rbx)
5056
5157 addq $16, %rbx
5258 sidt (%rbx)
5359
60+ leaq 1f(%rip), %rbp
61+
5462 /*
5563 * Switch to IDT and GDT with 32-bit segments. This is the firmware GDT
5664 * and IDT that was installed when the kernel started executing. The
arch/x86/include/asm/efi.h+10−4
@@ -46,13 +46,14 @@ extern unsigned long efi_mixed_mode_stack_pa; · 45 unmodified lines
4646
4747 #define __efi_nargs(...) __efi_nargs_(__VA_ARGS__)
4848 #define __efi_nargs_(...) __efi_nargs__(0, ##__VA_ARGS__, \
49+ __efi_arg_sentinel(9), __efi_arg_sentinel(8), \
4950 __efi_arg_sentinel(7), __efi_arg_sentinel(6), \
5051 __efi_arg_sentinel(5), __efi_arg_sentinel(4), \
5152 __efi_arg_sentinel(3), __efi_arg_sentinel(2), \
5253 __efi_arg_sentinel(1), __efi_arg_sentinel(0))
53−#define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, n, ...) \
54+#define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, ...) \
5455 __take_second_arg(n, \
55− ({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 8; }))
56+ ({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 10; }))
5657 #define __efi_arg_sentinel(n) , n
5758
5859 /*
@@ -176,8 +177,9 @@ extern u64 efi_setup; · 117 unmodified lines
176177 extern efi_status_t __efi64_thunk(u32, ...);
177178
178179 #define efi64_thunk(...) ({ \
179− __efi_nargs_check(efi64_thunk, 6, __VA_ARGS__); \
180− __efi64_thunk(__VA_ARGS__); \
180+ u64 __pad[3]; /* must have space for 3 args on the stack */ \
181+ __efi_nargs_check(efi64_thunk, 9, __VA_ARGS__); \
182+ __efi64_thunk(__VA_ARGS__, __pad); \
181183 })
182184
183185 static inline bool efi_is_mixed(void)
@@ -306,6 +308,10 @@ static inline u32 efi64_convert_status(efi_status_t status) · 122 unmodified lines
306308 #define __efi64_argmap_query_mode(gop, mode, size, info) \
307309 ((gop), (mode), efi64_zero_upper(size), efi64_zero_upper(info))
308310
311+/* TCG2 protocol */
312+#define __efi64_argmap_hash_log_extend_event(prot, fl, addr, size, ev) \
313+ ((prot), (fl), 0ULL, (u64)(addr), 0ULL, (u64)(size), 0ULL, ev)
314+
309315 /*
310316 * The macros below handle the plumbing for the argument mapping. To add a
311317 * mapping for a specific EFI method, simply define a macro
arch/x86/platform/efi/efi_thunk_64.S+12−2
@@ -36,6 +36,17 @@ SYM_CODE_START(__efi64_thunk) · 35 unmodified lines
3636 movq efi_mixed_mode_stack_pa(%rip), %rsp
3737 push %rax
3838
39+ /*
40+ * Copy args passed via the stack
41+ */
42+ subq $0x24, %rsp
43+ movq 0x18(%rax), %rbp
44+ movq 0x20(%rax), %rbx
45+ movq 0x28(%rax), %rax
46+ movl %ebp, 0x18(%rsp)
47+ movl %ebx, 0x1c(%rsp)
48+ movl %eax, 0x20(%rsp)
49+
3950 /*
4051 * Calculate the physical address of the kernel text.
4152 */
@@ -47,7 +58,6 @@ SYM_CODE_START(__efi64_thunk) · 5 unmodified lines
4758 subq %rax, %rbp
4859 subq %rax, %rbx
4960
50− subq $28, %rsp
5161 movl %ebx, 0x0(%rsp) /* return address */
5262 movl %esi, 0x4(%rsp)
5363 movl %edx, 0x8(%rsp)
@@ -60,7 +70,7 @@ SYM_CODE_START(__efi64_thunk) · 6 unmodified lines
6070 pushq %rdi /* EFI runtime service address */
6171 lretq
6272
63−1: movq 24(%rsp), %rsp
73+1: movq 0x20(%rsp), %rsp
6474 pop %rbx
6575 pop %rbp
6676 retq
drivers/firmware/efi/efivars.c+2−1
@@ -352,11 +352,12 @@ static struct attribute *def_attrs[] = { · 351 unmodified lines
352352 &efivar_attr_raw_var.attr,
353353 NULL,
354354 };
355+ATTRIBUTE_GROUPS(def);
355356
356357 static struct kobj_type efivar_ktype = {
357358 .release = efivar_release,
358359 .sysfs_ops = &efivar_attr_ops,
359− .default_attrs = def_attrs,
360+ .default_groups = def_groups,
360361 };
361362
362363 static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
drivers/firmware/efi/esrt.c+3−1
@@ -146,6 +146,8 @@ static struct attribute *esre1_attrs[] = { · 145 unmodified lines
146146 &esre_last_attempt_status.attr,
147147 NULL
148148 };
149+ATTRIBUTE_GROUPS(esre1);
150+
149151 static void esre_release(struct kobject *kobj)
150152 {
151153 struct esre_entry *entry = to_entry(kobj);
@@ -157,7 +159,7 @@ static void esre_release(struct kobject *kobj) · 5 unmodified lines
157159 static struct kobj_type esre1_ktype = {
158160 .release = esre_release,
159161 .sysfs_ops = &esre_attr_ops,
160− .default_attrs = esre1_attrs,
162+ .default_groups = esre1_groups,
161163 };
162164
163165
drivers/firmware/efi/libstub/efi-stub-helper.c+61−12
@@ -20,10 +20,10 @@ · 19 unmodified lines
2020
2121 bool efi_nochunk;
2222 bool efi_nokaslr = !IS_ENABLED(CONFIG_RANDOMIZE_BASE);
23−bool efi_noinitrd;
2423 int efi_loglevel = CONSOLE_LOGLEVEL_DEFAULT;
2524 bool efi_novamap;
2625
26+static bool efi_noinitrd;
2727 static bool efi_nosoftreserve;
2828 static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
2929
@@ -625,6 +625,47 @@ efi_status_t efi_load_initrd_cmdline(efi_loaded_image_t *image, · 595 unmodified lines
625625 load_addr, load_size);
626626 }
627627
628+static const struct {
629+ efi_tcg2_event_t event_data;
630+ efi_tcg2_tagged_event_t tagged_event;
631+ u8 tagged_event_data[];
632+} initrd_tcg2_event = {
633+ {
634+ sizeof(initrd_tcg2_event) + sizeof("Linux initrd"),
635+ {
636+ sizeof(initrd_tcg2_event.event_data.event_header),
637+ EFI_TCG2_EVENT_HEADER_VERSION,
638+ 9,
639+ EV_EVENT_TAG,
640+ },
641+ },
642+ {
643+ INITRD_EVENT_TAG_ID,
644+ sizeof("Linux initrd"),
645+ },
646+ { "Linux initrd" },
647+};
648+
649+static void efi_measure_initrd(unsigned long load_addr, unsigned long load_size)
650+{
651+ efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID;
652+ efi_tcg2_protocol_t *tcg2 = NULL;
653+ efi_status_t status;
654+
655+ efi_bs_call(locate_protocol, &tcg2_guid, NULL, (void **)&tcg2);
656+ if (tcg2) {
657+ status = efi_call_proto(tcg2, hash_log_extend_event,
658+ 0, load_addr, load_size,
659+ &initrd_tcg2_event.event_data);
660+ if (status != EFI_SUCCESS)
661+ efi_warn("Failed to measure initrd data: 0x%lx\n",
662+ status);
663+ else
664+ efi_info("Measured initrd data into PCR %d\n",
665+ initrd_tcg2_event.event_data.event_header.pcr_index);
666+ }
667+}
668+
628669 /**
629670 * efi_load_initrd() - Load initial RAM disk
630671 * @image: EFI loaded image protocol
@@ -643,17 +684,25 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image, · 12 unmodified lines
643684 {
644685 efi_status_t status;
645686
646− if (!load_addr || !load_size)
647− return EFI_INVALID_PARAMETER;
648−
649− status = efi_load_initrd_dev_path(load_addr, load_size, hard_limit);
650− if (status == EFI_SUCCESS) {
651− efi_info("Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path\n");
652− } else if (status == EFI_NOT_FOUND) {
653− status = efi_load_initrd_cmdline(image, load_addr, load_size,
654− soft_limit, hard_limit);
655− if (status == EFI_SUCCESS && *load_size > 0)
656− efi_info("Loaded initrd from command line option\n");
687+ if (efi_noinitrd) {
688+ *load_addr = *load_size = 0;
689+ status = EFI_SUCCESS;
690+ } else {
691+ status = efi_load_initrd_dev_path(load_addr, load_size, hard_limit);
692+ if (status == EFI_SUCCESS) {
693+ efi_info("Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path\n");
694+ if (*load_size > 0)
695+ efi_measure_initrd(*load_addr, *load_size);
696+ } else if (status == EFI_NOT_FOUND) {
697+ status = efi_load_initrd_cmdline(image, load_addr, load_size,
698+ soft_limit, hard_limit);
699+ if (status == EFI_SUCCESS && *load_size > 0)
700+ efi_info("Loaded initrd from command line option\n");
701+ }
702+ if (status != EFI_SUCCESS) {
703+ efi_err("Failed to load initrd: 0x%lx\n", status);
704+ *load_addr = *load_size = 0;
705+ }
657706 }
658707
659708 return status;
drivers/firmware/efi/libstub/efi-stub.c+2−8
@@ -134,7 +134,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, · 133 unmodified lines
134134 enum efi_secureboot_mode secure_boot;
135135 struct screen_info *si;
136136 efi_properties_table_t *prop_tbl;
137− unsigned long max_addr;
138137
139138 efi_system_table = sys_table_arg;
140139
@@ -240,13 +239,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, · 99 unmodified lines
240239 if (!fdt_addr)
241240 efi_info("Generating empty DTB\n");
242241
243− if (!efi_noinitrd) {
244− max_addr = efi_get_max_initrd_addr(image_addr);
245− status = efi_load_initrd(image, &initrd_addr, &initrd_size,
246− ULONG_MAX, max_addr);
247− if (status != EFI_SUCCESS)
248− efi_err("Failed to load initrd!\n");
249− }
242+ efi_load_initrd(image, &initrd_addr, &initrd_size, ULONG_MAX,
243+ efi_get_max_initrd_addr(image_addr));
250244
251245 efi_random_get_seed();
252246
drivers/firmware/efi/libstub/efistub.h+28−2
@@ -31,7 +31,6 @@ · 30 unmodified lines
3131
3232 extern bool efi_nochunk;
3333 extern bool efi_nokaslr;
34−extern bool efi_noinitrd;
3534 extern int efi_loglevel;
3635 extern bool efi_novamap;
3736
@@ -667,6 +666,29 @@ union apple_properties_protocol { · 629 unmodified lines
667666
668667 typedef u32 efi_tcg2_event_log_format;
669668
669+#define INITRD_EVENT_TAG_ID 0x8F3B22ECU
670+#define EV_EVENT_TAG 0x00000006U
671+#define EFI_TCG2_EVENT_HEADER_VERSION 0x1
672+
673+struct efi_tcg2_event {
674+ u32 event_size;
675+ struct {
676+ u32 header_size;
677+ u16 header_version;
678+ u32 pcr_index;
679+ u32 event_type;
680+ } __packed event_header;
681+ /* u8[] event follows here */
682+} __packed;
683+
684+struct efi_tcg2_tagged_event {
685+ u32 tagged_event_id;
686+ u32 tagged_event_data_size;
687+ /* u8 tagged event data follows here */
688+} __packed;
689+
690+typedef struct efi_tcg2_event efi_tcg2_event_t;
691+typedef struct efi_tcg2_tagged_event efi_tcg2_tagged_event_t;
670692 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
671693
672694 union efi_tcg2_protocol {
@@ -677,7 +699,11 @@ union efi_tcg2_protocol { · 4 unmodified lines
677699 efi_physical_addr_t *,
678700 efi_physical_addr_t *,
679701 efi_bool_t *);
680− void *hash_log_extend_event;
702+ efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,
703+ u64,
704+ efi_physical_addr_t,
705+ u64,
706+ const efi_tcg2_event_t *);
681707 void *submit_command;
682708 void *get_active_pcr_banks;
683709 void *set_active_pcr_banks;
drivers/firmware/efi/libstub/x86-stub.c+10−16
@@ -673,6 +673,7 @@ unsigned long efi_main(efi_handle_t handle, · 672 unmodified lines
673673 unsigned long bzimage_addr = (unsigned long)startup_32;
674674 unsigned long buffer_start, buffer_end;
675675 struct setup_header *hdr = &boot_params->hdr;
676+ unsigned long addr, size;
676677 efi_status_t status;
677678
678679 efi_system_table = sys_table_arg;
@@ -761,22 +762,15 @@ unsigned long efi_main(efi_handle_t handle, · 82 unmodified lines
761762 * arguments will be processed only if image is not NULL, which will be
762763 * the case only if we were loaded via the PE entry point.
763764 */
764− if (!efi_noinitrd) {
765− unsigned long addr, size;
766−
767− status = efi_load_initrd(image, &addr, &size,
768− hdr->initrd_addr_max, ULONG_MAX);
769−
770− if (status != EFI_SUCCESS) {
771− efi_err("Failed to load initrd!\n");
772− goto fail;
773− }
774− if (size > 0) {
775− efi_set_u64_split(addr, &hdr->ramdisk_image,
776− &boot_params->ext_ramdisk_image);
777− efi_set_u64_split(size, &hdr->ramdisk_size,
778− &boot_params->ext_ramdisk_size);
779− }
765+ status = efi_load_initrd(image, &addr, &size, hdr->initrd_addr_max,
766+ ULONG_MAX);
767+ if (status != EFI_SUCCESS)
768+ goto fail;
769+ if (size > 0) {
770+ efi_set_u64_split(addr, &hdr->ramdisk_image,
771+ &boot_params->ext_ramdisk_image);
772+ efi_set_u64_split(size, &hdr->ramdisk_size,
773+ &boot_params->ext_ramdisk_size);
780774 }
781775
782776 /*
drivers/firmware/efi/runtime-map.c+2−1
@@ -79,6 +79,7 @@ static struct attribute *def_attrs[] = { · 78 unmodified lines
7979 &map_attribute_attr.attr,
8080 NULL
8181 };
82+ATTRIBUTE_GROUPS(def);
8283
8384 static const struct sysfs_ops map_attr_ops = {
8485 .show = map_attr_show,
@@ -94,7 +95,7 @@ static void map_release(struct kobject *kobj) · 9 unmodified lines
9495
9596 static struct kobj_type __refdata map_ktype = {
9697 .sysfs_ops = &map_attr_ops,
97− .default_attrs = def_attrs,
98+ .default_groups = def_groups,
9899 .release = map_release,
99100 };
100101
include/linux/efi.h+3−3
@@ -570,8 +570,8 @@ extern struct efi { · 569 unmodified lines
570570 unsigned long flags;
571571 } efi;
572572
573−#define EFI_RT_SUPPORTED_GET_TIME 0x0001
574−#define EFI_RT_SUPPORTED_SET_TIME 0x0002
573+#define EFI_RT_SUPPORTED_GET_TIME 0x0001
574+#define EFI_RT_SUPPORTED_SET_TIME 0x0002
575575 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
576576 #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
577577 #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
@@ -838,7 +838,7 @@ extern int efi_status_to_err(efi_status_t status); · 260 unmodified lines
838838 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
839839 #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
840840
841−#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
841+#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
842842 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
843843 EFI_VARIABLE_RUNTIME_ACCESS | \
844844 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t