Skip to content

Commit 4ccb43f

Browse files
Linn Crosettovijay-suman
authored andcommitted
arm64: add kernel config option to lock down when in Secure Boot mode
Add a kernel configuration option to lock down the kernel, to restrict userspace's ability to modify the running kernel when UEFI Secure Boot is enabled. Based on the x86 patch by Matthew Garrett. Determine the state of Secure Boot in the EFI stub and pass this to the kernel using the FDT. Signed-off-by: Linn Crosetto <[email protected]> [bwh: Forward-ported to 4.10: adjust context] [Lukas Wunner: Forward-ported to 4.11: drop parts applied upstream] [bwh: Forward-ported to 4.15 and lockdown patch set: - Pass result of efi_get_secureboot() in stub through to efi_set_secure_boot() in main kernel - Use lockdown API and naming] [bwh: Forward-ported to 4.19.3: adjust context in update_fdt()] [dannf: Moved init_lockdown() call after uefi_init(), fixing SB detection] [bwh: Drop call to init_lockdown(), as efi_set_secure_boot() now calls this] [bwh: Forward-ported to 5.6: efi_get_secureboot() no longer takes a sys_table parameter] [bwh: Forward-ported to 5.7: EFI initialisation from FDT was rewritten, so: - Add Secure Boot mode to the parameter enumeration in fdtparams.c - Add a parameter to efi_get_fdt_params() to return the Secure Boot mode - Since Xen does not have a property name defined for Secure Boot mode, change efi_get_fdt_prop() to handle a missing property name by clearing the output variable] [Salvatore Bonaccorso: Forward-ported to 5.10: f30f242 ("efi: Rename arm-init to efi-init common for all arch") renamed arm-init.c to efi-init.c] Orabug: 34304810 Signed-off-by: Eric Snowberg <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent d700828 commit 4ccb43f

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

drivers/firmware/efi/efi-init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ void __init efi_init(void)
213213
{
214214
struct efi_memory_map_data data;
215215
u64 efi_system_table;
216+
u32 secure_boot;
216217

217218
/* Grab UEFI information placed in FDT by stub */
218-
efi_system_table = efi_get_fdt_params(&data);
219+
efi_system_table = efi_get_fdt_params(&data, &secure_boot);
219220
if (!efi_system_table)
220221
return;
221222

@@ -237,6 +238,8 @@ void __init efi_init(void)
237238
return;
238239
}
239240

241+
efi_set_secure_boot(secure_boot);
242+
240243
reserve_regions();
241244
/*
242245
* For memblock manipulation, the cap should come after the memblock_add().

drivers/firmware/efi/fdtparams.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum {
1616
MMSIZE,
1717
DCSIZE,
1818
DCVERS,
19+
SBMODE,
1920

2021
PARAMCOUNT
2122
};
@@ -26,6 +27,7 @@ static __initconst const char name[][22] = {
2627
[MMSIZE] = "MemMap Size ",
2728
[DCSIZE] = "MemMap Desc. Size ",
2829
[DCVERS] = "MemMap Desc. Version ",
30+
[SBMODE] = "Secure Boot Enabled ",
2931
};
3032

3133
static __initconst const struct {
@@ -43,6 +45,7 @@ static __initconst const struct {
4345
[MMSIZE] = "xen,uefi-mmap-size",
4446
[DCSIZE] = "xen,uefi-mmap-desc-size",
4547
[DCVERS] = "xen,uefi-mmap-desc-ver",
48+
[SBMODE] = "",
4649
}
4750
}, {
4851
#endif
@@ -53,6 +56,7 @@ static __initconst const struct {
5356
[MMSIZE] = "linux,uefi-mmap-size",
5457
[DCSIZE] = "linux,uefi-mmap-desc-size",
5558
[DCVERS] = "linux,uefi-mmap-desc-ver",
59+
[SBMODE] = "linux,uefi-secure-boot",
5660
}
5761
}
5862
};
@@ -64,6 +68,11 @@ static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname,
6468
int len;
6569
u64 val;
6670

71+
if (!pname[0]) {
72+
memset(var, 0, size);
73+
return 0;
74+
}
75+
6776
prop = fdt_getprop(fdt, node, pname, &len);
6877
if (!prop)
6978
return 1;
@@ -81,7 +90,7 @@ static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname,
8190
return 0;
8291
}
8392

84-
u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm)
93+
u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm, u32 *secure_boot)
8594
{
8695
const void *fdt = initial_boot_params;
8796
unsigned long systab;
@@ -95,6 +104,7 @@ u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm)
95104
[MMSIZE] = { &mm->size, sizeof(mm->size) },
96105
[DCSIZE] = { &mm->desc_size, sizeof(mm->desc_size) },
97106
[DCVERS] = { &mm->desc_version, sizeof(mm->desc_version) },
107+
[SBMODE] = { secure_boot, sizeof(*secure_boot) },
98108
};
99109

100110
BUILD_BUG_ON(ARRAY_SIZE(target) != ARRAY_SIZE(name));

drivers/firmware/efi/libstub/fdt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size,
132132
}
133133
}
134134

135+
fdt_val32 = cpu_to_fdt32(efi_get_secureboot());
136+
status = fdt_setprop(fdt, node, "linux,uefi-secure-boot",
137+
&fdt_val32, sizeof(fdt_val32));
138+
if (status)
139+
goto fdt_set_fail;
140+
135141
/* Shrink the FDT back to its minimum size: */
136142
fdt_pack(fdt);
137143

include/linux/efi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
764764
extern int __efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
765765
extern void efi_mem_reserve(phys_addr_t addr, u64 size);
766766
extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
767-
extern u64 efi_get_fdt_params(struct efi_memory_map_data *data);
767+
extern u64 efi_get_fdt_params(struct efi_memory_map_data *data, u32 *secure_boot);
768768
extern struct kobject *efi_kobj;
769769

770770
extern int efi_reboot_quirk_mode;

0 commit comments

Comments
 (0)