Skip to content

Commit 39b66a2

Browse files
bwhacksPlaidCat
authored andcommitted
efi: Lock down the kernel if booted in secure boot mode
jira LE-2629 feature Additional SecureBoot patches for dynamic lockdown commit 78c8af872660c31779951583b6f1ebf283d95985 commit-source https://salsa.debian.org/kernel-team/linux.git commit-patch-path debian/patches/features/all/lockdown commit-info Checkout the commit sha above and move to the directory listed above to find Debian patches matching this commits summary line. Based on an earlier patch by David Howells, who wrote the following description: > UEFI Secure Boot provides a mechanism for ensuring that the firmware will > only load signed bootloaders and kernels. Certain use cases may also > require that all kernel modules also be signed. Add a configuration option > that to lock down the kernel - which includes requiring validly signed > modules - if the kernel is secure-booted. Signed-off-by: Ben Hutchings <[email protected]> [Salvatore Bonaccorso: After fixing https://bugs.debian.org/956197 the help text for LOCK_DOWN_IN_EFI_SECURE_BOOT was adjusted to mention that lockdown is triggered in integrity mode (https://bugs.debian.org/1025417)] Signed-off-by: Salvatore Bonaccorso <[email protected]> Signed-off-by: Jonathan Maple <[email protected]>
1 parent e3a39db commit 39b66a2

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

arch/x86/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ void __init setup_arch(char **cmdline_p)
904904
if (efi_enabled(EFI_BOOT))
905905
efi_init();
906906

907+
efi_set_secure_boot(boot_params.secure_boot);
908+
907909
reserve_ibft_region();
908910
x86_init.resources.dmi_setup();
909911

@@ -1070,8 +1072,6 @@ void __init setup_arch(char **cmdline_p)
10701072
/* Allocate bigger log buffer */
10711073
setup_log_buf(1);
10721074

1073-
efi_set_secure_boot(boot_params.secure_boot);
1074-
10751075
reserve_initrd();
10761076

10771077
acpi_table_upgrade();

drivers/firmware/efi/secureboot.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/efi.h>
1616
#include <linux/kernel.h>
1717
#include <linux/printk.h>
18+
#include <linux/security.h>
1819

1920
/*
2021
* Decide what to do when UEFI secure boot mode is enabled.
@@ -28,6 +29,10 @@ void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
2829
break;
2930
case efi_secureboot_mode_enabled:
3031
set_bit(EFI_SECURE_BOOT, &efi.flags);
32+
#ifdef CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT
33+
lock_kernel_down("EFI Secure Boot",
34+
LOCKDOWN_INTEGRITY_MAX);
35+
#endif
3136
pr_info("Secure boot enabled\n");
3237
break;
3338
default:

include/linux/security.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
522522
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
523523
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
524524
int security_locked_down(enum lockdown_reason what);
525+
int lock_kernel_down(const char *where, enum lockdown_reason level);
525526
int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len,
526527
void *val, size_t val_len, u64 id, u64 flags);
527528
int security_bdev_alloc(struct block_device *bdev);
@@ -1504,6 +1505,11 @@ static inline int security_locked_down(enum lockdown_reason what)
15041505
{
15051506
return 0;
15061507
}
1508+
static inline int
1509+
lock_kernel_down(const char *where, enum lockdown_reason level)
1510+
{
1511+
return -EOPNOTSUPP;
1512+
}
15071513
static inline int lsm_fill_user_ctx(struct lsm_ctx __user *uctx,
15081514
u32 *uctx_len, void *val, size_t val_len,
15091515
u64 id, u64 flags)

security/lockdown/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ config LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY
4545
disabled.
4646

4747
endchoice
48+
49+
config LOCK_DOWN_IN_EFI_SECURE_BOOT
50+
bool "Lock down the kernel in EFI Secure Boot mode"
51+
default n
52+
depends on SECURITY_LOCKDOWN_LSM
53+
depends on EFI
54+
select SECURITY_LOCKDOWN_LSM_EARLY
55+
help
56+
UEFI Secure Boot provides a mechanism for ensuring that the firmware
57+
will only load signed bootloaders and kernels. Secure boot mode may
58+
be determined from EFI variables provided by the system firmware if
59+
not indicated by the boot parameters.
60+
61+
Enabling this option results in kernel lockdown being
62+
triggered in integrity mode if EFI Secure Boot is set.

security/lockdown/lockdown.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static const enum lockdown_reason lockdown_levels[] = {LOCKDOWN_NONE,
2424
/*
2525
* Put the kernel into lock-down mode.
2626
*/
27-
static int lock_kernel_down(const char *where, enum lockdown_reason level)
27+
int lock_kernel_down(const char *where, enum lockdown_reason level)
2828
{
2929
if (kernel_locked_down >= level)
3030
return -EPERM;

0 commit comments

Comments
 (0)