]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ima: Reset IMA_NONACTION_RULE_FLAGS after post_setattr
authorRoberto Sassu <roberto.sassu@huawei.com>
Tue, 4 Feb 2025 12:57:20 +0000 (13:57 +0100)
committerMimi Zohar <zohar@linux.ibm.com>
Wed, 5 Feb 2025 02:36:43 +0000 (21:36 -0500)
Commit 0d73a55208e9 ("ima: re-introduce own integrity cache lock")
mistakenly reverted the performance improvement introduced in commit
42a4c603198f0 ("ima: fix ima_inode_post_setattr"). The unused bit mask was
subsequently removed by commit 11c60f23ed13 ("integrity: Remove unused
macro IMA_ACTION_RULE_FLAGS").

Restore the performance improvement by introducing the new mask
IMA_NONACTION_RULE_FLAGS, equal to IMA_NONACTION_FLAGS without
IMA_NEW_FILE, which is not a rule-specific flag.

Finally, reset IMA_NONACTION_RULE_FLAGS instead of IMA_NONACTION_FLAGS in
process_measurement(), if the IMA_CHANGE_ATTR atomic flag is set (after
file metadata modification).

With this patch, new files for which metadata were modified while they are
still open, can be reopened before the last file close (when security.ima
is written), since the IMA_NEW_FILE flag is not cleared anymore. Otherwise,
appraisal fails because security.ima is missing (files with IMA_NEW_FILE
set are an exception).

Cc: stable@vger.kernel.org # v4.16.x
Fixes: 0d73a55208e9 ("ima: re-introduce own integrity cache lock")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
security/integrity/ima/ima.h
security/integrity/ima/ima_main.c

index 24d09ea91b8773db3df8e0a6f62be946ac3d3269..a4f284bd846c154f1b1627456e1b8faa31eb30a3 100644 (file)
@@ -149,6 +149,9 @@ struct ima_kexec_hdr {
 #define IMA_CHECK_BLACKLIST    0x40000000
 #define IMA_VERITY_REQUIRED    0x80000000
 
+/* Exclude non-action flags which are not rule-specific. */
+#define IMA_NONACTION_RULE_FLAGS       (IMA_NONACTION_FLAGS & ~IMA_NEW_FILE)
+
 #define IMA_DO_MASK            (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \
                                 IMA_HASH | IMA_APPRAISE_SUBMASK)
 #define IMA_DONE_MASK          (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \
index f2c9affa0c2ac61e2c800a6d3a975caf102928ab..28b8b0db6f9bbc502b4703dc336225a87fc266c4 100644 (file)
@@ -269,10 +269,13 @@ static int process_measurement(struct file *file, const struct cred *cred,
        mutex_lock(&iint->mutex);
 
        if (test_and_clear_bit(IMA_CHANGE_ATTR, &iint->atomic_flags))
-               /* reset appraisal flags if ima_inode_post_setattr was called */
+               /*
+                * Reset appraisal flags (action and non-action rule-specific)
+                * if ima_inode_post_setattr was called.
+                */
                iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED |
                                 IMA_APPRAISE_SUBMASK | IMA_APPRAISED_SUBMASK |
-                                IMA_NONACTION_FLAGS);
+                                IMA_NONACTION_RULE_FLAGS);
 
        /*
         * Re-evaulate the file if either the xattr has changed or the