]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
ima: add support for measuring and appraising firmware
authorMimi Zohar <zohar@linux.vnet.ibm.com>
Tue, 22 Jul 2014 14:39:48 +0000 (10:39 -0400)
committerKees Cook <keescook@chromium.org>
Fri, 25 Jul 2014 18:47:46 +0000 (11:47 -0700)
The "security: introduce kernel_fw_from_file hook" patch defined a
new security hook to evaluate any loaded firmware that wasn't built
into the kernel.

This patch defines ima_fw_from_file(), which is called from the new
security hook, to measure and/or appraise the loaded firmware's
integrity.

Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Documentation/ABI/testing/ima_policy
include/linux/ima.h
security/integrity/ima/ima.h
security/integrity/ima/ima_appraise.c
security/integrity/ima/ima_main.c
security/integrity/ima/ima_policy.c
security/integrity/integrity.h
security/security.c

index 4c3efe4348060a10d1282059967b3725f5f41e34..d0d0c578324c7437324d5a23f1536cc1f0f2a08d 100644 (file)
@@ -26,6 +26,7 @@ Description:
                        option: [[appraise_type=]] [permit_directio]
 
                base:   func:= [BPRM_CHECK][MMAP_CHECK][FILE_CHECK][MODULE_CHECK]
+                               [FIRMWARE_CHECK]
                        mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
                        fsmagic:= hex value
                        fsuuid:= file system UUID (e.g 8bcbe394-4f13-4144-be8e-5aa9ea2ce2f6)
@@ -57,7 +58,8 @@ Description:
                        measure func=BPRM_CHECK
                        measure func=FILE_MMAP mask=MAY_EXEC
                        measure func=FILE_CHECK mask=MAY_READ uid=0
-                       measure func=MODULE_CHECK uid=0
+                       measure func=MODULE_CHECK
+                       measure func=FIRMWARE_CHECK
                        appraise fowner=0
 
                The default policy measures all executables in bprm_check,
index 1b7f268cddce7535dd25d2fa61fc80aaa8c2cfda..7cf5e9b3255013deb9b4feac058112f5d7acdc5a 100644 (file)
@@ -19,6 +19,7 @@ extern int ima_file_check(struct file *file, int mask);
 extern void ima_file_free(struct file *file);
 extern int ima_file_mmap(struct file *file, unsigned long prot);
 extern int ima_module_check(struct file *file);
+extern int ima_fw_from_file(struct file *file, char *buf, size_t size);
 
 #else
 static inline int ima_bprm_check(struct linux_binprm *bprm)
@@ -46,6 +47,11 @@ static inline int ima_module_check(struct file *file)
        return 0;
 }
 
+static inline int ima_fw_from_file(struct file *file, char *buf, size_t size)
+{
+       return 0;
+}
+
 #endif /* CONFIG_IMA */
 
 #ifdef CONFIG_IMA_APPRAISE
index c42056edfc97699a7e85d7c1826614ef3686981f..57da4bd7ba0c9cf0c465daaceeaaa77cdfe5f21d 100644 (file)
@@ -158,7 +158,7 @@ struct integrity_iint_cache *integrity_iint_insert(struct inode *inode);
 struct integrity_iint_cache *integrity_iint_find(struct inode *inode);
 
 /* IMA policy related functions */
-enum ima_hooks { FILE_CHECK = 1, MMAP_CHECK, BPRM_CHECK, MODULE_CHECK, POST_SETATTR };
+enum ima_hooks { FILE_CHECK = 1, MMAP_CHECK, BPRM_CHECK, MODULE_CHECK, FIRMWARE_CHECK, POST_SETATTR };
 
 int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
                     int flags);
@@ -171,6 +171,7 @@ void ima_delete_rules(void);
 #define IMA_APPRAISE_ENFORCE   0x01
 #define IMA_APPRAISE_FIX       0x02
 #define IMA_APPRAISE_MODULES   0x04
+#define IMA_APPRAISE_FIRMWARE  0x08
 
 #ifdef CONFIG_IMA_APPRAISE
 int ima_appraise_measurement(int func, struct integrity_iint_cache *iint,
index 59ac902750703a7d7a74dddfcdeb6b132f270af5..86bfd5c5df85e0bec07bc6be5e7ab58bd98c945c 100644 (file)
@@ -75,6 +75,8 @@ enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint,
                return iint->ima_bprm_status;
        case MODULE_CHECK:
                return iint->ima_module_status;
+       case FIRMWARE_CHECK:
+               return iint->ima_firmware_status;
        case FILE_CHECK:
        default:
                return iint->ima_file_status;
@@ -94,6 +96,9 @@ static void ima_set_cache_status(struct integrity_iint_cache *iint,
        case MODULE_CHECK:
                iint->ima_module_status = status;
                break;
+       case FIRMWARE_CHECK:
+               iint->ima_firmware_status = status;
+               break;
        case FILE_CHECK:
        default:
                iint->ima_file_status = status;
@@ -113,6 +118,9 @@ static void ima_cache_flags(struct integrity_iint_cache *iint, int func)
        case MODULE_CHECK:
                iint->flags |= (IMA_MODULE_APPRAISED | IMA_APPRAISED);
                break;
+       case FIRMWARE_CHECK:
+               iint->flags |= (IMA_FIRMWARE_APPRAISED | IMA_APPRAISED);
+               break;
        case FILE_CHECK:
        default:
                iint->flags |= (IMA_FILE_APPRAISED | IMA_APPRAISED);
index 0d696431209c09e1ac3f1c55145544648dbfa3be..2917f980bf3075c3dacff3531cf03d8e4e39e6f6 100644 (file)
@@ -319,6 +319,17 @@ int ima_module_check(struct file *file)
        return process_measurement(file, NULL, MAY_EXEC, MODULE_CHECK);
 }
 
+int ima_fw_from_file(struct file *file, char *buf, size_t size)
+{
+       if (!file) {
+               if ((ima_appraise & IMA_APPRAISE_FIRMWARE) &&
+                   (ima_appraise & IMA_APPRAISE_ENFORCE))
+                       return -EACCES; /* INTEGRITY_UNKNOWN */
+               return 0;
+       }
+       return process_measurement(file, NULL, MAY_EXEC, FIRMWARE_CHECK);
+}
+
 static int __init init_ima(void)
 {
        int error;
index cea84d8bd7be7426863ba0be3de0262961fb9ae9..07099a8bc2835d8a8bb0ef3f7ec2f826796fd270 100644 (file)
@@ -84,6 +84,7 @@ static struct ima_rule_entry default_rules[] = {
        {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ, .uid = GLOBAL_ROOT_UID,
         .flags = IMA_FUNC | IMA_MASK | IMA_UID},
        {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
+       {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
 };
 
 static struct ima_rule_entry default_appraise_rules[] = {
@@ -241,6 +242,8 @@ static int get_subaction(struct ima_rule_entry *rule, int func)
                return IMA_BPRM_APPRAISE;
        case MODULE_CHECK:
                return IMA_MODULE_APPRAISE;
+       case FIRMWARE_CHECK:
+               return IMA_FIRMWARE_APPRAISE;
        case FILE_CHECK:
        default:
                return IMA_FILE_APPRAISE;
@@ -486,6 +489,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
                                entry->func = FILE_CHECK;
                        else if (strcmp(args[0].from, "MODULE_CHECK") == 0)
                                entry->func = MODULE_CHECK;
+                       else if (strcmp(args[0].from, "FIRMWARE_CHECK") == 0)
+                               entry->func = FIRMWARE_CHECK;
                        else if ((strcmp(args[0].from, "FILE_MMAP") == 0)
                                || (strcmp(args[0].from, "MMAP_CHECK") == 0))
                                entry->func = MMAP_CHECK;
@@ -636,6 +641,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
                result = -EINVAL;
        else if (entry->func == MODULE_CHECK)
                ima_appraise |= IMA_APPRAISE_MODULES;
+       else if (entry->func == FIRMWARE_CHECK)
+               ima_appraise |= IMA_APPRAISE_FIRMWARE;
        audit_log_format(ab, "res=%d", !result);
        audit_log_end(ab);
        return result;
index 09c440d9aaee5b3c1624a93c7cebd45f3cf0d1c6..19b8e314ca964efdff3cf7ddf30851f9f0e29d80 100644 (file)
 #define IMA_BPRM_APPRAISED     0x00002000
 #define IMA_MODULE_APPRAISE    0x00004000
 #define IMA_MODULE_APPRAISED   0x00008000
+#define IMA_FIRMWARE_APPRAISE  0x00010000
+#define IMA_FIRMWARE_APPRAISED 0x00020000
 #define IMA_APPRAISE_SUBMASK   (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \
-                                IMA_BPRM_APPRAISE | IMA_MODULE_APPRAISE)
+                                IMA_BPRM_APPRAISE | IMA_MODULE_APPRAISE | \
+                                IMA_FIRMWARE_APPRAISE)
 #define IMA_APPRAISED_SUBMASK  (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \
-                                IMA_BPRM_APPRAISED | IMA_MODULE_APPRAISED)
+                                IMA_BPRM_APPRAISED | IMA_MODULE_APPRAISED | \
+                                IMA_FIRMWARE_APPRAISED)
 
 enum evm_ima_xattr_type {
        IMA_XATTR_DIGEST = 0x01,
@@ -104,6 +108,7 @@ struct integrity_iint_cache {
        enum integrity_status ima_mmap_status:4;
        enum integrity_status ima_bprm_status:4;
        enum integrity_status ima_module_status:4;
+       enum integrity_status ima_firmware_status:4;
        enum integrity_status evm_status:4;
        struct ima_digest_data *ima_hash;
 };
index 35d37d0f0d491018491ee9ede72e91827f3d3ed7..e41b1a8d7644a674d8e9c02ae09fc3562d6a8d84 100644 (file)
@@ -847,7 +847,12 @@ int security_kernel_create_files_as(struct cred *new, struct inode *inode)
 
 int security_kernel_fw_from_file(struct file *file, char *buf, size_t size)
 {
-       return security_ops->kernel_fw_from_file(file, buf, size);
+       int ret;
+
+       ret = security_ops->kernel_fw_from_file(file, buf, size);
+       if (ret)
+               return ret;
+       return ima_fw_from_file(file, buf, size);
 }
 EXPORT_SYMBOL_GPL(security_kernel_fw_from_file);