Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Copyright (C) 2018 IBM Corporation
0004  */
0005 #include <linux/efi.h>
0006 #include <linux/module.h>
0007 #include <linux/ima.h>
0008 #include <asm/efi.h>
0009 
0010 #ifndef arch_ima_efi_boot_mode
0011 #define arch_ima_efi_boot_mode efi_secureboot_mode_unset
0012 #endif
0013 
0014 static enum efi_secureboot_mode get_sb_mode(void)
0015 {
0016     enum efi_secureboot_mode mode;
0017 
0018     if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) {
0019         pr_info("ima: secureboot mode unknown, no efi\n");
0020         return efi_secureboot_mode_unknown;
0021     }
0022 
0023     mode = efi_get_secureboot_mode(efi.get_variable);
0024     if (mode == efi_secureboot_mode_disabled)
0025         pr_info("ima: secureboot mode disabled\n");
0026     else if (mode == efi_secureboot_mode_unknown)
0027         pr_info("ima: secureboot mode unknown\n");
0028     else
0029         pr_info("ima: secureboot mode enabled\n");
0030     return mode;
0031 }
0032 
0033 bool arch_ima_get_secureboot(void)
0034 {
0035     static enum efi_secureboot_mode sb_mode;
0036     static bool initialized;
0037 
0038     if (!initialized && efi_enabled(EFI_BOOT)) {
0039         sb_mode = arch_ima_efi_boot_mode;
0040 
0041         if (sb_mode == efi_secureboot_mode_unset)
0042             sb_mode = get_sb_mode();
0043         initialized = true;
0044     }
0045 
0046     if (sb_mode == efi_secureboot_mode_enabled)
0047         return true;
0048     else
0049         return false;
0050 }
0051 
0052 /* secureboot arch rules */
0053 static const char * const sb_arch_rules[] = {
0054 #if !IS_ENABLED(CONFIG_KEXEC_SIG)
0055     "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
0056 #endif /* CONFIG_KEXEC_SIG */
0057     "measure func=KEXEC_KERNEL_CHECK",
0058 #if !IS_ENABLED(CONFIG_MODULE_SIG)
0059     "appraise func=MODULE_CHECK appraise_type=imasig",
0060 #endif
0061     "measure func=MODULE_CHECK",
0062     NULL
0063 };
0064 
0065 const char * const *arch_get_ima_policy(void)
0066 {
0067     if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
0068         if (IS_ENABLED(CONFIG_MODULE_SIG))
0069             set_module_sig_enforced();
0070         if (IS_ENABLED(CONFIG_KEXEC_SIG))
0071             set_kexec_sig_enforced();
0072         return sb_arch_rules;
0073     }
0074     return NULL;
0075 }