efi: Add a function to check if Secure Boot mode is enabled

Also cache it to avoid needing to repeatedly ask the firmware.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Gerald Elder-Vass <gerald.elder-vass@cloud.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Ross Lagerwall authored and Andrew Cooper committed 2025-09-05 23:45:38 +01:00
1 parent 5104e05904
commit cb41b4ce14
3 files changed
+27

No files matched your search

+24
View File
@@ -901,6 +901,28 @@ static void __init pre_parse(const struct file *file)
" last line will be ignored.\r\n");
}
static void __init init_secure_boot_mode(void)
{
static EFI_GUID __initdata gv_uuid = EFI_GLOBAL_VARIABLE;
static CHAR16 __initdata str_SecureBoot[] = L"SecureBoot";
EFI_STATUS status;
uint8_t data = 0;
UINTN size = sizeof(data);
UINT32 attr = 0;
status = efi_rs->GetVariable(str_SecureBoot, &gv_uuid, &attr, &size, &data);
if ( status == EFI_NOT_FOUND ||
(status == EFI_SUCCESS &&
attr == (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS) &&
size == 1 && data == 0) )
/* Platform does not support Secure Boot or it's disabled. */
efi_secure_boot = false;
else
/* Everything else play it safe and assume enabled. */
efi_secure_boot = true;
}
static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
efi_ih = ImageHandle;
@@ -915,6 +937,8 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl
StdOut = SystemTable->ConOut;
StdErr = SystemTable->StdErr ?: StdOut;
init_secure_boot_mode();
}
static void __init efi_console_set_mode(void)
+1
View File
@@ -41,6 +41,7 @@ void efi_rs_leave(struct efi_rs_state *state);
unsigned int __read_mostly efi_num_ct;
const EFI_CONFIGURATION_TABLE *__read_mostly efi_ct;
bool __ro_after_init efi_secure_boot;
unsigned int __read_mostly efi_version;
unsigned int __read_mostly efi_fw_revision;
const CHAR16 *__read_mostly efi_fw_vendor;
+2
View File
@@ -36,6 +36,8 @@ static inline bool efi_enabled(unsigned int feature)
}
#endif
extern bool efi_secure_boot;
void efi_init_memory(void);
bool efi_boot_mem_unused(unsigned long *start, unsigned long *end);
bool efi_rs_using_pgtables(void);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.