From: Mimi Zohar <zohar@linux.ibm.com>
To: linux-integrity@vger.kernel.org
Cc: Mimi Zohar <zohar@linux.ibm.com>,
Frederick Lawler <fred@cloudflare.com>,
Jeff Layton <jlayton@kernel.org>,
Roberto Sassu <roberto.sassu@huaweicloud.com>
Subject: [PATCH] ima: fallback to using i_version
Date: Thu, 12 Feb 2026 15:11:00 -0500 [thread overview]
Message-ID: <20260212201100.881432-1-zohar@linux.ibm.com> (raw)
Commit db1d1e8b9867 ("IMA: use vfs_getattr_nosec to get the i_version")
replaced detecting file change based on i_version with
STATX_CHANGE_COOKIE.
On filesystems without STATX_CHANGE_COOKIE enabled, revert back to
detecting file change based on i_version.
Fixes: db1d1e8b9867 ("IMA: use vfs_getattr_nosec to get the i_version")
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
security/integrity/ima/ima_api.c | 13 ++++++++----
security/integrity/ima/ima_main.c | 34 +++++++++++++++++++++++++------
2 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
index c35ea613c9f8..3f0c73a8b459 100644
--- a/security/integrity/ima/ima_api.c
+++ b/security/integrity/ima/ima_api.c
@@ -267,15 +267,20 @@ int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file,
goto out;
/*
- * Detecting file change is based on i_version. On filesystems
- * which do not support i_version, support was originally limited
- * to an initial measurement/appraisal/audit, but was modified to
- * assume the file changed.
+ * Detect file change based on STATX_CHANGE_COOKIE, when supported,
+ * and fallback to detecting file change based on i_version.
+ *
+ * On filesystems which did not support i_version, support was
+ * originally limited to an initial measurement/appraisal/audit,
+ * but was later modified to assume the file changed.
*/
result = vfs_getattr_nosec(&file->f_path, &stat, STATX_CHANGE_COOKIE,
AT_STATX_SYNC_AS_STAT);
if (!result && (stat.result_mask & STATX_CHANGE_COOKIE))
i_version = stat.change_cookie;
+ else if (IS_I_VERSION(inode))
+ i_version = inode_peek_iversion(inode);
+
hash.hdr.algo = algo;
hash.hdr.length = hash_digest_size[algo];
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 1d6229b156fb..fc50f727c954 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -184,7 +184,9 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
struct inode *inode, struct file *file)
{
fmode_t mode = file->f_mode;
+ int modified = 0;
bool update;
+ int result;
if (!(mode & FMODE_WRITE))
return;
@@ -197,12 +199,32 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
update = test_and_clear_bit(IMA_UPDATE_XATTR,
&iint->atomic_flags);
- if ((iint->flags & IMA_NEW_FILE) ||
- vfs_getattr_nosec(&file->f_path, &stat,
- STATX_CHANGE_COOKIE,
- AT_STATX_SYNC_AS_STAT) ||
- !(stat.result_mask & STATX_CHANGE_COOKIE) ||
- stat.change_cookie != iint->real_inode.version) {
+
+ if (iint->flags & IMA_NEW_FILE)
+ modified = 1;
+
+ /*
+ * Detect file change based on STATX_CHANGE_COOKIE, when
+ * supported, and fallback to detecting file change based
+ * on i_version. On filesystems which do not support either,
+ * assume the file changed.
+ */
+ result = vfs_getattr_nosec(&file->f_path, &stat,
+ STATX_CHANGE_COOKIE,
+ AT_STATX_SYNC_AS_STAT);
+
+ if (!result && stat.result_mask & STATX_CHANGE_COOKIE &&
+ stat.change_cookie != iint->real_inode.version)
+ modified = 1;
+ else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
+ IS_I_VERSION(inode) &&
+ !(inode_eq_iversion(inode, iint->real_inode.version)))
+ modified = 1;
+ else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
+ !(IS_I_VERSION(inode)))
+ modified = 1;
+
+ if (modified) {
iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
iint->measured_pcrs = 0;
if (update)
--
2.53.0
reply other threads:[~2026-02-12 20:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260212201100.881432-1-zohar@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=fred@cloudflare.com \
--cc=jlayton@kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=roberto.sassu@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox