Skip to content

Commit 2450fc0

Browse files
dhowellsvijay-suman
authored andcommitted
efi: Add an EFI_SECURE_BOOT flag to indicate secure boot mode
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. Upstream Status: RHEL only Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> cc: [email protected] [Rebased for context; efi_is_table_address was moved to arch/x86] Signed-off-by: Jeremy Cline <[email protected]> (cherry picked from commit 53250b991f841be025fa4d264850dadc0fae2861 from https://gitlab.com/cki-project/kernel-ark) Signed-off-by: Paolo Pisati <[email protected]> [Call efi_set_secure_boot immediately after efi_init] Orabug: 34304810 Signed-off-by: Eric Snowberg <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent f9f2ab6 commit 2450fc0

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

arch/x86/kernel/setup.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ void __init setup_arch(char **cmdline_p)
905905
if (efi_enabled(EFI_BOOT))
906906
efi_init();
907907

908+
efi_set_secure_boot(boot_params.secure_boot);
908909
reserve_ibft_region();
909910
x86_init.resources.dmi_setup();
910911

@@ -1073,20 +1074,6 @@ void __init setup_arch(char **cmdline_p)
10731074
/* Allocate bigger log buffer */
10741075
setup_log_buf(1);
10751076

1076-
if (efi_enabled(EFI_BOOT)) {
1077-
switch (boot_params.secure_boot) {
1078-
case efi_secureboot_mode_disabled:
1079-
pr_info("Secure boot disabled\n");
1080-
break;
1081-
case efi_secureboot_mode_enabled:
1082-
pr_info("Secure boot enabled\n");
1083-
break;
1084-
default:
1085-
pr_info("Secure boot could not be determined\n");
1086-
break;
1087-
}
1088-
}
1089-
10901077
reserve_initrd();
10911078

10921079
acpi_table_upgrade();

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

include/linux/efi.h

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

879887
#ifdef CONFIG_EFI
880888
/*
@@ -886,6 +894,8 @@ static inline bool efi_enabled(int feature)
886894
}
887895
extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
888896

897+
extern void __init efi_set_secure_boot(enum efi_secureboot_mode mode);
898+
889899
bool __pure __efi_soft_reserve_enabled(void);
890900

891901
static inline bool __pure efi_soft_reserve_enabled(void)
@@ -907,6 +917,8 @@ static inline bool efi_enabled(int feature)
907917
static inline void
908918
efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
909919

920+
static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {}
921+
910922
static inline bool efi_soft_reserve_enabled(void)
911923
{
912924
return false;
@@ -1136,13 +1148,6 @@ static inline bool efi_runtime_disabled(void) { return true; }
11361148
extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
11371149
extern unsigned long efi_call_virt_save_flags(void);
11381150

1139-
enum efi_secureboot_mode {
1140-
efi_secureboot_mode_unset,
1141-
efi_secureboot_mode_unknown,
1142-
efi_secureboot_mode_disabled,
1143-
efi_secureboot_mode_enabled,
1144-
};
1145-
11461151
static inline
11471152
enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var)
11481153
{

0 commit comments

Comments
 (0)