Skip to content

Commit 7e30101

Browse files
dhowellsPlaidCat
authored andcommitted
efi: Add an EFI_SECURE_BOOT flag to indicate 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 UEFI machines can be booted in Secure Boot mode. Add an EFI_SECURE_BOOT flag that can be passed to efi_enabled() to find out whether secure boot is enabled. Move the switch-statement in x86's setup_arch() that inteprets the secure_boot boot parameter to generic code and set the bit there. Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> cc: [email protected] [rperier: Forward-ported to 5.5: - Use pr_warn() - Adjust context] [bwh: Forward-ported to 5.6: adjust context] [bwh: Forward-ported to 5.7: - Use the next available bit in efi.flags - Adjust context] Signed-off-by: Jonathan Maple <[email protected]>
1 parent ef51294 commit 7e30101

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

arch/x86/kernel/setup.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,19 +1070,7 @@ void __init setup_arch(char **cmdline_p)
10701070
/* Allocate bigger log buffer */
10711071
setup_log_buf(1);
10721072

1073-
if (efi_enabled(EFI_BOOT)) {
1074-
switch (boot_params.secure_boot) {
1075-
case efi_secureboot_mode_disabled:
1076-
pr_info("Secure boot disabled\n");
1077-
break;
1078-
case efi_secureboot_mode_enabled:
1079-
pr_info("Secure boot enabled\n");
1080-
break;
1081-
default:
1082-
pr_info("Secure boot could not be determined\n");
1083-
break;
1084-
}
1085-
}
1073+
efi_set_secure_boot(boot_params.secure_boot);
10861074

10871075
reserve_initrd();
10881076

drivers/firmware/efi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ subdir-$(CONFIG_EFI_STUB) += libstub
2525
obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o
2626
obj-$(CONFIG_EFI_TEST) += test/
2727
obj-$(CONFIG_EFI_DEV_PATH_PARSER) += dev-path-parser.o
28+
obj-$(CONFIG_EFI) += secureboot.o
2829
obj-$(CONFIG_APPLE_PROPERTIES) += apple-properties.o
2930
obj-$(CONFIG_EFI_RCI2_TABLE) += rci2-table.o
3031
obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += embedded-firmware.o

drivers/firmware/efi/secureboot.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
/* Core kernel secure boot support.
3+
*
4+
* Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
5+
* Written by David Howells ([email protected])
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public Licence
9+
* as published by the Free Software Foundation; either version
10+
* 2 of the Licence, or (at your option) any later version.
11+
*/
12+
13+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14+
15+
#include <linux/efi.h>
16+
#include <linux/kernel.h>
17+
#include <linux/printk.h>
18+
19+
/*
20+
* Decide what to do when UEFI secure boot mode is enabled.
21+
*/
22+
void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
23+
{
24+
if (efi_enabled(EFI_BOOT)) {
25+
switch (mode) {
26+
case efi_secureboot_mode_disabled:
27+
pr_info("Secure boot disabled\n");
28+
break;
29+
case efi_secureboot_mode_enabled:
30+
set_bit(EFI_SECURE_BOOT, &efi.flags);
31+
pr_info("Secure boot enabled\n");
32+
break;
33+
default:
34+
pr_warn("Secure boot could not be determined (mode %u)\n",
35+
mode);
36+
break;
37+
}
38+
}
39+
}

include/linux/efi.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,14 @@ static inline int efi_range_is_wc(unsigned long start, unsigned long len)
876876
#define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
877877
#define EFI_MEM_NO_SOFT_RESERVE 11 /* Is the kernel configured to ignore soft reservations? */
878878
#define EFI_PRESERVE_BS_REGIONS 12 /* Are EFI boot-services memory segments available? */
879+
#define EFI_SECURE_BOOT 13 /* Are we in Secure Boot mode? */
880+
881+
enum efi_secureboot_mode {
882+
efi_secureboot_mode_unset,
883+
efi_secureboot_mode_unknown,
884+
efi_secureboot_mode_disabled,
885+
efi_secureboot_mode_enabled,
886+
};
879887

880888
#ifdef CONFIG_EFI
881889
/*
@@ -900,6 +908,7 @@ static inline bool efi_rt_services_supported(unsigned int mask)
900908
return (efi.runtime_supported_mask & mask) == mask;
901909
}
902910
extern void efi_find_mirror(void);
911+
extern void __init efi_set_secure_boot(enum efi_secureboot_mode mode);
903912
#else
904913
static inline bool efi_enabled(int feature)
905914
{
@@ -919,6 +928,7 @@ static inline bool efi_rt_services_supported(unsigned int mask)
919928
}
920929

921930
static inline void efi_find_mirror(void) {}
931+
static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {}
922932
#endif
923933

924934
extern int efi_status_to_err(efi_status_t status);
@@ -1137,13 +1147,6 @@ static inline bool efi_runtime_disabled(void) { return true; }
11371147
extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
11381148
extern unsigned long efi_call_virt_save_flags(void);
11391149

1140-
enum efi_secureboot_mode {
1141-
efi_secureboot_mode_unset,
1142-
efi_secureboot_mode_unknown,
1143-
efi_secureboot_mode_disabled,
1144-
efi_secureboot_mode_enabled,
1145-
};
1146-
11471150
static inline
11481151
enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var)
11491152
{

0 commit comments

Comments
 (0)