Linux filesystem development
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Josef Bacik <josef@bacik.io>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Christian Brauner <brauner@kernel.org>,
	driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernfs: refresh the inode before changing attributes
Date: Thu, 03 Dec 2026 09:03:42 -1000	[thread overview]
Message-ID: <1347ee3f0a83e14e2ef5db37147e3966@kernel.org> (raw)
In-Reply-To: <20261203-b4-kernfs-setattr-refresh-v1-1-b66a2529427e@bacik.io>

On Thu, Dec 03, 2026 at 10:51:06AM -0500, Josef Bacik wrote:
> The owner and mode of a node are kept in the kernfs_node. An inode only
> has a copy, which ->permission() and ->getattr() bring up to date.
> kernfs_iop_setattr() does not, so setattr_prepare() can go by old values
> and, for one, fail a chmod by the owner of the node with EPERM.
>
> Refresh the inode first. notify_change() has looked at the copy as well
> by then, so compute the mode for ATTR_KILL_S[UG]ID and check ATTR_TOUCH
> again.
>
> Fixes: 3ff195b011d7 ("sysfs: Implement sysfs tagged directory support.")
> Signed-off-by: Josef Bacik <josef@bacik.io>

Acked-by: Tejun Heo <tj@kernel.org>

> +	if (ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
> +		iattr->ia_mode = inode->i_mode;
> +		if (ia_valid & ATTR_KILL_SUID)
> +			iattr->ia_mode &= ~S_ISUID;
> +		if (ia_valid & ATTR_KILL_SGID)
> +			iattr->ia_mode &= ~S_ISGID;
> +	}

notify_change() also decides whether to set ATTR_MODE from the old i_mode
and that part isn't redone. If the cached mode has no setuid bit and the
node has one, a chown leaves the bit in place. The other way around,
ATTR_MODE stays set and the chown fails with -EPERM for a caller without
CAP_FOWNER. Both behave the same without the patch, so a follow-up is fine.
Maybe clear ATTR_MODE here and set it again from the refreshed mode?

Thanks.

--
tejun

      reply	other threads:[~2026-12-03 19:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 15:51 [PATCH] kernfs: refresh the inode before changing attributes Josef Bacik
2026-12-03 19:03 ` Tejun Heo [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=1347ee3f0a83e14e2ef5db37147e3966@kernel.org \
    --to=tj@kernel.org \
    --cc=brauner@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=josef@bacik.io \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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