Skip to content

Commit 57a0ef0

Browse files
robertosassumimizohar
authored andcommitted
ima: Reset IMA_NONACTION_RULE_FLAGS after post_setattr
Commit 0d73a55 ("ima: re-introduce own integrity cache lock") mistakenly reverted the performance improvement introduced in commit 42a4c60 ("ima: fix ima_inode_post_setattr"). The unused bit mask was subsequently removed by commit 11c60f2 ("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: 0d73a55 ("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>
1 parent ceb5fae commit 57a0ef0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

security/integrity/ima/ima.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ struct ima_kexec_hdr {
149149
#define IMA_CHECK_BLACKLIST 0x40000000
150150
#define IMA_VERITY_REQUIRED 0x80000000
151151

152+
/* Exclude non-action flags which are not rule-specific. */
153+
#define IMA_NONACTION_RULE_FLAGS (IMA_NONACTION_FLAGS & ~IMA_NEW_FILE)
154+
152155
#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \
153156
IMA_HASH | IMA_APPRAISE_SUBMASK)
154157
#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \

security/integrity/ima/ima_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,13 @@ static int process_measurement(struct file *file, const struct cred *cred,
269269
mutex_lock(&iint->mutex);
270270

271271
if (test_and_clear_bit(IMA_CHANGE_ATTR, &iint->atomic_flags))
272-
/* reset appraisal flags if ima_inode_post_setattr was called */
272+
/*
273+
* Reset appraisal flags (action and non-action rule-specific)
274+
* if ima_inode_post_setattr was called.
275+
*/
273276
iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED |
274277
IMA_APPRAISE_SUBMASK | IMA_APPRAISED_SUBMASK |
275-
IMA_NONACTION_FLAGS);
278+
IMA_NONACTION_RULE_FLAGS);
276279

277280
/*
278281
* Re-evaulate the file if either the xattr has changed or the

0 commit comments

Comments
 (0)