Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2019 IBM Corporation
0004  * Author: Nayna Jain
0005  */
0006 
0007 #include <linux/ima.h>
0008 #include <asm/secure_boot.h>
0009 
0010 bool arch_ima_get_secureboot(void)
0011 {
0012     return is_ppc_secureboot_enabled();
0013 }
0014 
0015 /*
0016  * The "secure_rules" are enabled only on "secureboot" enabled systems.
0017  * These rules verify the file signatures against known good values.
0018  * The "appraise_type=imasig|modsig" option allows the known good signature
0019  * to be stored as an xattr or as an appended signature.
0020  *
0021  * To avoid duplicate signature verification as much as possible, the IMA
0022  * policy rule for module appraisal is added only if CONFIG_MODULE_SIG
0023  * is not enabled.
0024  */
0025 static const char *const secure_rules[] = {
0026     "appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
0027 #ifndef CONFIG_MODULE_SIG
0028     "appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
0029 #endif
0030     NULL
0031 };
0032 
0033 /*
0034  * The "trusted_rules" are enabled only on "trustedboot" enabled systems.
0035  * These rules add the kexec kernel image and kernel modules file hashes to
0036  * the IMA measurement list.
0037  */
0038 static const char *const trusted_rules[] = {
0039     "measure func=KEXEC_KERNEL_CHECK",
0040     "measure func=MODULE_CHECK",
0041     NULL
0042 };
0043 
0044 /*
0045  * The "secure_and_trusted_rules" contains rules for both the secure boot and
0046  * trusted boot. The "template=ima-modsig" option includes the appended
0047  * signature, when available, in the IMA measurement list.
0048  */
0049 static const char *const secure_and_trusted_rules[] = {
0050     "measure func=KEXEC_KERNEL_CHECK template=ima-modsig",
0051     "measure func=MODULE_CHECK template=ima-modsig",
0052     "appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
0053 #ifndef CONFIG_MODULE_SIG
0054     "appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
0055 #endif
0056     NULL
0057 };
0058 
0059 /*
0060  * Returns the relevant IMA arch-specific policies based on the system secure
0061  * boot state.
0062  */
0063 const char *const *arch_get_ima_policy(void)
0064 {
0065     if (is_ppc_secureboot_enabled()) {
0066         if (IS_ENABLED(CONFIG_MODULE_SIG))
0067             set_module_sig_enforced();
0068 
0069         if (is_ppc_trustedboot_enabled())
0070             return secure_and_trusted_rules;
0071         else
0072             return secure_rules;
0073     } else if (is_ppc_trustedboot_enabled()) {
0074         return trusted_rules;
0075     }
0076 
0077     return NULL;
0078 }