Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorri...
[sfrench/cifs-2.6.git] / security / integrity / ima / ima_main.c
index 1b88d58e132586c9d588d959bdc7644186345e80..4ffac4f5c647eb9e68c5938501890917d52ad940 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * Integrity Measurement Architecture
+ *
  * Copyright (C) 2005,2006,2007,2008 IBM Corporation
  *
  * Authors:
@@ -103,7 +105,7 @@ static void ima_rdwr_violation_check(struct file *file,
        } else {
                if (must_measure)
                        set_bit(IMA_MUST_MEASURE, &iint->atomic_flags);
-               if ((atomic_read(&inode->i_writecount) > 0) && must_measure)
+               if (inode_is_open_for_write(inode) && must_measure)
                        send_writers = true;
        }
 
@@ -505,20 +507,26 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,
  */
 int ima_load_data(enum kernel_load_data_id id)
 {
-       bool sig_enforce;
+       bool ima_enforce, sig_enforce;
 
-       if ((ima_appraise & IMA_APPRAISE_ENFORCE) != IMA_APPRAISE_ENFORCE)
-               return 0;
+       ima_enforce =
+               (ima_appraise & IMA_APPRAISE_ENFORCE) == IMA_APPRAISE_ENFORCE;
 
        switch (id) {
        case LOADING_KEXEC_IMAGE:
-               if (ima_appraise & IMA_APPRAISE_KEXEC) {
+               if (IS_ENABLED(CONFIG_KEXEC_VERIFY_SIG)
+                   && arch_ima_get_secureboot()) {
+                       pr_err("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n");
+                       return -EACCES;
+               }
+
+               if (ima_enforce && (ima_appraise & IMA_APPRAISE_KEXEC)) {
                        pr_err("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n");
                        return -EACCES; /* INTEGRITY_UNKNOWN */
                }
                break;
        case LOADING_FIRMWARE:
-               if (ima_appraise & IMA_APPRAISE_FIRMWARE) {
+               if (ima_enforce && (ima_appraise & IMA_APPRAISE_FIRMWARE)) {
                        pr_err("Prevent firmware sysfs fallback loading.\n");
                        return -EACCES; /* INTEGRITY_UNKNOWN */
                }
@@ -526,7 +534,8 @@ int ima_load_data(enum kernel_load_data_id id)
        case LOADING_MODULE:
                sig_enforce = is_module_sig_enforced();
 
-               if (!sig_enforce && (ima_appraise & IMA_APPRAISE_MODULES)) {
+               if (ima_enforce && (!sig_enforce
+                                   && (ima_appraise & IMA_APPRAISE_MODULES))) {
                        pr_err("impossible to appraise a module without a file descriptor. sig_enforce kernel parameter might help\n");
                        return -EACCES; /* INTEGRITY_UNKNOWN */
                }
@@ -560,6 +569,3 @@ static int __init init_ima(void)
 }
 
 late_initcall(init_ima);       /* Start IMA after the TPM is available */
-
-MODULE_DESCRIPTION("Integrity Measurement Architecture");
-MODULE_LICENSE("GPL");