1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2018 IBM Corporation
6 #include <linux/module.h>
9 extern struct boot_params boot_params;
11 static enum efi_secureboot_mode get_sb_mode(void)
13 efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
16 u8 secboot, setupmode;
18 size = sizeof(secboot);
20 if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) {
21 pr_info("ima: secureboot mode unknown, no efi\n");
22 return efi_secureboot_mode_unknown;
25 /* Get variable contents into buffer */
26 status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
27 NULL, &size, &secboot);
28 if (status == EFI_NOT_FOUND) {
29 pr_info("ima: secureboot mode disabled\n");
30 return efi_secureboot_mode_disabled;
33 if (status != EFI_SUCCESS) {
34 pr_info("ima: secureboot mode unknown\n");
35 return efi_secureboot_mode_unknown;
38 size = sizeof(setupmode);
39 status = efi.get_variable(L"SetupMode", &efi_variable_guid,
40 NULL, &size, &setupmode);
42 if (status != EFI_SUCCESS) /* ignore unknown SetupMode */
45 if (secboot == 0 || setupmode == 1) {
46 pr_info("ima: secureboot mode disabled\n");
47 return efi_secureboot_mode_disabled;
50 pr_info("ima: secureboot mode enabled\n");
51 return efi_secureboot_mode_enabled;
54 bool arch_ima_get_secureboot(void)
56 static enum efi_secureboot_mode sb_mode;
57 static bool initialized;
59 if (!initialized && efi_enabled(EFI_BOOT)) {
60 sb_mode = boot_params.secure_boot;
62 if (sb_mode == efi_secureboot_mode_unset)
63 sb_mode = get_sb_mode();
67 if (sb_mode == efi_secureboot_mode_enabled)
73 /* secureboot arch rules */
74 static const char * const sb_arch_rules[] = {
75 #if !IS_ENABLED(CONFIG_KEXEC_SIG)
76 "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
77 #endif /* CONFIG_KEXEC_SIG */
78 "measure func=KEXEC_KERNEL_CHECK",
79 #if !IS_ENABLED(CONFIG_MODULE_SIG)
80 "appraise func=MODULE_CHECK appraise_type=imasig",
82 "measure func=MODULE_CHECK",
86 const char * const *arch_get_ima_policy(void)
88 if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
89 if (IS_ENABLED(CONFIG_MODULE_SIG))
90 set_module_sig_enforced();
91 if (IS_ENABLED(CONFIG_KEXEC_SIG))
92 set_kexec_sig_enforced();