treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / x86 / kernel / ima_arch.c
blob4d4f5d9faac314ad5fe5c21a05e72c873ec42d65
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * Copyright (C) 2018 IBM Corporation
4 */
5 #include <linux/efi.h>
6 #include <linux/module.h>
7 #include <linux/ima.h>
9 extern struct boot_params boot_params;
11 static enum efi_secureboot_mode get_sb_mode(void)
13 efi_char16_t efi_SecureBoot_name[] = L"SecureBoot";
14 efi_char16_t efi_SetupMode_name[] = L"SecureBoot";
15 efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
16 efi_status_t status;
17 unsigned long size;
18 u8 secboot, setupmode;
20 size = sizeof(secboot);
22 if (!efi_enabled(EFI_RUNTIME_SERVICES)) {
23 pr_info("ima: secureboot mode unknown, no efi\n");
24 return efi_secureboot_mode_unknown;
27 /* Get variable contents into buffer */
28 status = efi.get_variable(efi_SecureBoot_name, &efi_variable_guid,
29 NULL, &size, &secboot);
30 if (status == EFI_NOT_FOUND) {
31 pr_info("ima: secureboot mode disabled\n");
32 return efi_secureboot_mode_disabled;
35 if (status != EFI_SUCCESS) {
36 pr_info("ima: secureboot mode unknown\n");
37 return efi_secureboot_mode_unknown;
40 size = sizeof(setupmode);
41 status = efi.get_variable(efi_SetupMode_name, &efi_variable_guid,
42 NULL, &size, &setupmode);
44 if (status != EFI_SUCCESS) /* ignore unknown SetupMode */
45 setupmode = 0;
47 if (secboot == 0 || setupmode == 1) {
48 pr_info("ima: secureboot mode disabled\n");
49 return efi_secureboot_mode_disabled;
52 pr_info("ima: secureboot mode enabled\n");
53 return efi_secureboot_mode_enabled;
56 bool arch_ima_get_secureboot(void)
58 static enum efi_secureboot_mode sb_mode;
59 static bool initialized;
61 if (!initialized && efi_enabled(EFI_BOOT)) {
62 sb_mode = boot_params.secure_boot;
64 if (sb_mode == efi_secureboot_mode_unset)
65 sb_mode = get_sb_mode();
66 initialized = true;
69 if (sb_mode == efi_secureboot_mode_enabled)
70 return true;
71 else
72 return false;
75 /* secureboot arch rules */
76 static const char * const sb_arch_rules[] = {
77 #if !IS_ENABLED(CONFIG_KEXEC_SIG)
78 "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
79 #endif /* CONFIG_KEXEC_SIG */
80 "measure func=KEXEC_KERNEL_CHECK",
81 #if !IS_ENABLED(CONFIG_MODULE_SIG)
82 "appraise func=MODULE_CHECK appraise_type=imasig",
83 #endif
84 "measure func=MODULE_CHECK",
85 NULL
88 const char * const *arch_get_ima_policy(void)
90 if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
91 if (IS_ENABLED(CONFIG_MODULE_SIG))
92 set_module_sig_enforced();
93 return sb_arch_rules;
95 return NULL;