Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Alan <3164729207@qq.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: restore the old mode if the ACL update fails
Date: Wed, 02 Dec 2026 15:37:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-246114@kernel.org> (raw)
In-Reply-To: <tencent_9246D288C7818FCDAA2F130315D73AFDEE05@qq.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ext4: restoring old_mode in ext4_setattr() re-enables
  S_ISUID/S_ISGID
--

commit 25d855847832145fc418799835c609dfdd478477
Author: Alan <3164729207@qq.com>

ext4: restore the old mode if the ACL update fails

This commit saves the previous inode->i_mode in ext4_setattr() and restores
it if posix_acl_chmod() fails after setattr_copy() has already dirtied the
new mode.

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index b4d581aa5ee1a..9de412540ddef 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -7029,6 +7029,7 @@ int ext4_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
>  		 struct iattr *attr)
>  {
>  	struct inode *inode = d_inode(dentry);
> +	umode_t old_mode = inode->i_mode;
>  	int error, rc = 0;
>  	int orphan = 0;
>  	const unsigned int ia_valid = attr->ia_valid;
> @@ -7173,8 +7174,19 @@ int ext4_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
>  	if (orphan && inode->i_nlink)
>  		ext4_orphan_del(NULL, inode);
>  
> -	if (!error && (ia_valid & ATTR_MODE))
> +	if (!error && (ia_valid & ATTR_MODE)) {
>  		rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
> +		if (rc) {
> +			/*
> +			 * The mode was already copied into the inode and marked
> +			 * dirty.  If the ACL update failed, chmod() returns an
> +			 * error but the new mode must not remain on disk while
> +			 * the ACL still describes the old mode.
> +			 */
> +			inode->i_mode = old_mode;
> +			mark_inode_dirty(inode);
> +		}
> +	}

[Severity: High]
Can restoring the full old_mode re-enable S_ISUID or S_ISGID after the file
has already been truncated or chowned?

During truncate() or chown() on a setuid or setgid file, notify_change()
translates ATTR_KILL_SUID and ATTR_KILL_SGID into ATTR_MODE with those bits
cleared in attr->ia_mode.  ext4_setattr() commits UID/GID updates and
performs truncation before calling setattr_copy() and posix_acl_chmod().

If posix_acl_chmod() then fails (for example with -ENOSPC when unsharing a
shared xattr block), writing back old_mode restores S_ISUID and S_ISGID on
an inode whose ownership or contents have already been modified on disk.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_9246D288C7818FCDAA2F130315D73AFDEE05@qq.com?part=1

      reply	other threads:[~2026-12-02 15:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:14 [PATCH] ext4: restore the old mode if the ACL update fails Alan
2026-12-02 15:37 ` sashiko-bot [this message]

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=sashiko-outbox-246114@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=3164729207@qq.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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