diff options
author | Jan Janssen <medhefgo@web.de> | 2021-10-20 10:11:45 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-10-22 10:08:38 +0200 |
commit | c49645121614c2ea0e04371a866c28cf87c9d7c5 (patch) | |
tree | 77356133c2a6ce03e85b0c491c27d4f2bd7d2db2 /src/basic/efivars.c | |
parent | Merge pull request #21081 from mrc0mmand/even-more-coverage-tweaks (diff) | |
download | systemd-c49645121614c2ea0e04371a866c28cf87c9d7c5.tar.xz systemd-c49645121614c2ea0e04371a866c28cf87c9d7c5.zip |
sd-boot: Be more precise about secure boot modes
Fixes: #11559
Diffstat (limited to 'src/basic/efivars.c')
-rw-r--r-- | src/basic/efivars.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/basic/efivars.c b/src/basic/efivars.c index 3e5c5e68dd..bb115a7b99 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -293,13 +293,28 @@ bool is_efi_secure_boot(void) { return cache > 0; } -bool is_efi_secure_boot_setup_mode(void) { - static int cache = -1; +SecureBootMode efi_get_secure_boot_mode(void) { + static SecureBootMode cache = _SECURE_BOOT_INVALID; - if (cache < 0) - cache = read_flag(EFI_GLOBAL_VARIABLE(SetupMode)); + if (cache != _SECURE_BOOT_INVALID) + return cache; - return cache > 0; + int secure = read_flag(EFI_GLOBAL_VARIABLE(SecureBoot)); + if (secure < 0) { + if (secure != -ENOENT) + log_debug_errno(secure, "Error reading SecureBoot EFI variable: %m"); + return (cache = SECURE_BOOT_UNSUPPORTED); + } + + /* We can assume false for all these if they are abscent (AuditMode and + * DeployedMode may not exist on older firmware). */ + int audit = read_flag(EFI_GLOBAL_VARIABLE(AuditMode)); + int deployed = read_flag(EFI_GLOBAL_VARIABLE(DeployedMode)); + int setup = read_flag(EFI_GLOBAL_VARIABLE(SetupMode)); + log_debug("Secure boot variables: SecureBoot=%d AuditMode=%d DeployedMode=%d SetupMode=%d", + secure, audit, deployed, setup); + + return (cache = decode_secure_boot_mode(secure, audit > 0, deployed > 0, setup > 0)); } static int read_efi_options_variable(char **line) { |