From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324624; b=tFUMD5b7BQ2Ium0P6I1Cvo6dymL2hk+dB/qCk2eZbSqvff8TGKKGKWxuIJJa5pGju1ma JcClcbT5SHgNIEyzPesJrRsuLF9SO2NvAlrYKzvVzpxFwO9Qe8mSNTaDjpgN+X2LWBh7a O0lDeHUHNpAbCzPLPjwiU5HU76GasxIHXgOKN1YM+qKQOjNXPDSL1eqkuk03Fe7jYA/GB ScZa8S7lLRpk+IKV0e7qJVOHrsI+e4RULmLRaaLLKN3JXjIuL2sXg/j6oBGMENTux/OSI I02xQwHM9vsoMNnXv2NFUHvWUmGwQw6pYQqFiW4BJnduwH31AkCG6ndx8nQ/JW+i77g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324624; h=Received:DKIM-Signature:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=onXa7Hju63L6pdFlg3ASIDf2isoBOY+OLI7vExEUyTs=; b=il2OJEBwRvRLpXWKNm/DKiWgaGTYboRWBtWMqBdLggLHlCrnGQddOifxQa9ohjm2VQRT 4idoAiU96n7+FVNnTCCqk0ZFxHTe4qQN+Ob9mefHJLg5X7HVyiN+iJwtoWKFNBb2JK7u3 eZ//tvfhehLypRBd2cRxp8HVSksr5fsAW+/ZDVjYSN7rW9GEXM3VOx3StXwcI9sH01BhT uzwH9AuX7b0srXncELNr+N+186xyJ9tIiXKQFVAHlRl9ADEPU+bMcHT7BTRcTuDm+GdGE X15Jmtb7pj/Um8C0cDNS7YaB7+2Mad8kuSO1+vmz6oPWmy8qyxU7dT1oO8QQvmwMyhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aueUOc7n; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E02B9606A322; Thu, 3 Dec 2026 19:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aueUOc7n Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1151B1F000C2; Thu, 3 Dec 2026 19:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796324623; bh=onXa7Hju63L6pdFlg3ASIDf2isoBOY+OLI7vExEUyTs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=aueUOc7nEz1ZCUlaHFsCXI/p8f+a8t7c/ajIwXBrjrxY2BiQWKws2lTKjqBR8Uf16 8baknzeJglP5OBRchJMojHDvcJBFf61ISfnSWR/85Uy5w6M+pTGHlcw0EojPrBlVIb GuOPKehmZCH/TCe8H6SP3vTeRxVq8PR4JSe65K2GK8LYBjRskLVTjMeERXjG5hocBi 2+MJOaY26jGVJM5nJYZpHXilq2sCjoGf1Pzm4gQOiFg0JHrSB+go7ppQ4kFOlL4v3l KnzVjkOb1Thhlyi8EdfSCA56nsmMwe6bQP/aK7gzuC6rmdGjlzCGAiwXaRuLOg6D6P Y9GyAbnyEyOJg== Date: Thu, 03 Dec 2026 09:03:42 -1000 Message-ID: <1347ee3f0a83e14e2ef5db37147e3966@kernel.org> From: Tejun Heo To: Josef Bacik Cc: Greg Kroah-Hartman , Christian Brauner , 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 In-Reply-To: <20261203-b4-kernfs-setattr-refresh-v1-1-b66a2529427e@bacik.io> References: <20261203-b4-kernfs-setattr-refresh-v1-1-b66a2529427e@bacik.io> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Acked-by: Tejun Heo > + 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