public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederick Lawler <fred@cloudflare.com>
To: Mimi Zohar <zohar@linux.ibm.com>
Cc: linux-integrity@vger.kernel.org, Jeff Layton <jlayton@kernel.org>,
	Roberto Sassu <roberto.sassu@huaweicloud.com>,
	Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [PATCH v2] ima: fallback to using i_version to detect file change
Date: Fri, 13 Feb 2026 13:51:02 -0600	[thread overview]
Message-ID: <aY-ApsCkJQ05-FIk@CMGLRV3> (raw)
In-Reply-To: <20260213174947.976924-1-zohar@linux.ibm.com>

On Fri, Feb 13, 2026 at 12:49:47PM -0500, Mimi Zohar wrote:
> 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.
> 
> On filesystems which do not support either, assume the file changed.
> 

Tested-by: Frederick Lawler <fred@cloudflare.com>

> Reported-by: Roberto Sassu <roberto.sassu@huawei.com>
> Fixes: db1d1e8b9867 ("IMA: use vfs_getattr_nosec to get the i_version")
> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
> ---
> Changelog v2:
> - Use the real_inode's iversion to detect file change on overlayfs
> - Add Roberto's Reported-by tag
> 
>  security/integrity/ima/ima_api.c  | 13 +++++++----
>  security/integrity/ima/ima_main.c | 39 ++++++++++++++++++++++++-------
>  2 files changed, 40 insertions(+), 12 deletions(-)
> 
> diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
> index c35ea613c9f8..28cf1fe07f8f 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(real_inode))
> +		i_version = inode_peek_iversion(real_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..4fc383479847 100644
> --- a/security/integrity/ima/ima_main.c
> +++ b/security/integrity/ima/ima_main.c
> @@ -180,6 +180,34 @@ static void ima_rdwr_violation_check(struct file *file,
>  				  "invalid_pcr", "open_writers");
>  }
>  
> +/*
> + * 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.
> + */
> +static bool ima_detect_file_change(struct ima_iint_cache *iint,
> +				   struct inode *inode, struct file *file)
> +{
> +	struct kstat stat;
> +	int result;
> +
> +	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)
> +		return true;
> +	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
> +		 IS_I_VERSION(inode) &&
> +		 !(inode_eq_iversion(inode, iint->real_inode.version)))
> +		return true;
> +	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
> +		 !(IS_I_VERSION(inode)))
> +		return true;
> +
> +	return false;
> +}
> +
>  static void ima_check_last_writer(struct ima_iint_cache *iint,
>  				  struct inode *inode, struct file *file)
>  {
> @@ -191,18 +219,13 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
>  
>  	mutex_lock(&iint->mutex);
>  	if (atomic_read(&inode->i_writecount) == 1) {
> -		struct kstat stat;
> -
>  		clear_bit(IMA_EMITTED_OPENWRITERS, &iint->atomic_flags);
>  
>  		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 ||
> +		    ima_detect_file_change(iint, inode, file)) {
>  			iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
>  			iint->measured_pcrs = 0;
>  			if (update)
> -- 
> 2.53.0
> 

  reply	other threads:[~2026-02-13 19:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-13 17:49 [PATCH v2] ima: fallback to using i_version to detect file change Mimi Zohar
2026-02-13 19:51 ` Frederick Lawler [this message]
2026-02-18 20:34   ` Mimi Zohar

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=aY-ApsCkJQ05-FIk@CMGLRV3 \
    --to=fred@cloudflare.com \
    --cc=jlayton@kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=zohar@linux.ibm.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