]> Git Repo - linux.git/blob - arch/x86/kernel/ima_arch.c
ath10k: sdio: workaround firmware UART pin configuration bug
[linux.git] / arch / x86 / kernel / ima_arch.c
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2018 IBM Corporation
4  */
5 #include <linux/efi.h>
6 #include <linux/ima.h>
7
8 extern struct boot_params boot_params;
9
10 static enum efi_secureboot_mode get_sb_mode(void)
11 {
12         efi_char16_t efi_SecureBoot_name[] = L"SecureBoot";
13         efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
14         efi_status_t status;
15         unsigned long size;
16         u8 secboot;
17
18         size = sizeof(secboot);
19
20         /* Get variable contents into buffer */
21         status = efi.get_variable(efi_SecureBoot_name, &efi_variable_guid,
22                                   NULL, &size, &secboot);
23         if (status == EFI_NOT_FOUND) {
24                 pr_info("ima: secureboot mode disabled\n");
25                 return efi_secureboot_mode_disabled;
26         }
27
28         if (status != EFI_SUCCESS) {
29                 pr_info("ima: secureboot mode unknown\n");
30                 return efi_secureboot_mode_unknown;
31         }
32
33         if (secboot == 0) {
34                 pr_info("ima: secureboot mode disabled\n");
35                 return efi_secureboot_mode_disabled;
36         }
37
38         pr_info("ima: secureboot mode enabled\n");
39         return efi_secureboot_mode_enabled;
40 }
41
42 bool arch_ima_get_secureboot(void)
43 {
44         static enum efi_secureboot_mode sb_mode;
45         static bool initialized;
46
47         if (!initialized && efi_enabled(EFI_BOOT)) {
48                 sb_mode = boot_params.secure_boot;
49
50                 if (sb_mode == efi_secureboot_mode_unset)
51                         sb_mode = get_sb_mode();
52                 initialized = true;
53         }
54
55         if (sb_mode == efi_secureboot_mode_enabled)
56                 return true;
57         else
58                 return false;
59 }
60
61 /* secureboot arch rules */
62 static const char * const sb_arch_rules[] = {
63 #if !IS_ENABLED(CONFIG_KEXEC_VERIFY_SIG)
64         "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
65 #endif /* CONFIG_KEXEC_VERIFY_SIG */
66         "measure func=KEXEC_KERNEL_CHECK",
67         NULL
68 };
69
70 const char * const *arch_get_ima_policy(void)
71 {
72         if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
73                 return sb_arch_rules;
74         return NULL;
75 }
This page took 0.03485 seconds and 4 git commands to generate.