@@ -179,6 +179,7 @@ struct ima_kexec_hdr {
#define IMA_CHANGE_ATTR 2
#define IMA_DIGSIG 3
#define IMA_MUST_MEASURE 4
+#define IMA_UPDATE_XATTR_FIX 5
/* IMA integrity metadata associated with an inode */
struct ima_iint_cache {
@@ -576,8 +576,10 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig &&
(!xattr_value ||
xattr_value->type != EVM_IMA_XATTR_DIGSIG)) {
- if (!ima_fix_xattr(dentry, iint))
- status = INTEGRITY_PASS;
+ /* Fix by setting security.ima on file close. */
+ set_bit(IMA_UPDATE_XATTR_FIX, &iint->atomic_flags);
+ status = INTEGRITY_PASS;
+ cause = "fix";
}
/*
@@ -587,6 +589,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
if (inode->i_size == 0 && iint->flags & IMA_NEW_FILE &&
test_bit(IMA_DIGSIG, &iint->atomic_flags)) {
status = INTEGRITY_PASS;
+ cause = "new-signed-file";
}
integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, filename,
@@ -158,13 +158,16 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
struct inode *inode, struct file *file)
{
fmode_t mode = file->f_mode;
- bool update;
+ bool update = false, update_fix;
- if (!(mode & FMODE_WRITE))
+ update_fix = test_and_clear_bit(IMA_UPDATE_XATTR_FIX,
+ &iint->atomic_flags);
+
+ if (!(mode & FMODE_WRITE) && !update_fix)
return;
ima_iint_lock(inode);
- if (atomic_read(&inode->i_writecount) == 1) {
+ if (atomic_read(&inode->i_writecount) == 1 && (mode & FMODE_WRITE)) {
struct kstat stat;
update = test_and_clear_bit(IMA_UPDATE_XATTR,
@@ -181,6 +184,10 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
ima_update_xattr(iint, file);
}
}
+
+ if (!update && update_fix)
+ ima_update_xattr(iint, file);
+
ima_iint_unlock(inode);
}
@@ -378,13 +385,10 @@ static int process_measurement(struct file *file, const struct cred *cred,
template_desc);
if (rc == 0 && (action & IMA_APPRAISE_SUBMASK)) {
rc = ima_check_blacklist(iint, modsig, pcr);
- if (rc != -EPERM) {
- inode_lock(inode);
+ if (rc != -EPERM)
rc = ima_appraise_measurement(func, iint, file,
pathname, xattr_value,
xattr_len, modsig);
- inode_unlock(inode);
- }
if (!rc)
rc = mmap_violation_check(func, file, &pathbuf,
&pathname, filename);