From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377118; b=T8xlZqQWP+ZXfuW5/iWwhBXtKcE/Dp7WtrOANGB+k1GDQ9KaDUB6Z7Eig+IBw/8MqQVD HtqHvJ2fGzWlQx1vVHDKChIkdJoMWzDsTxv9M2vQ40E7KiPA0ksS33VF1+pjn8Sz63Z6Q bXJmfrPeRV6IgERLGMWWUB+v7PIPs/P45osFtTAOeArs4zHJ0YZtImvcq8IH8+Eq5J2YQ ygPORfFsdsXIr0zKXr9Qg+nT5cg2oD2L5twCveD8I/mEZQ2mIZXgRsVpagkcmwnY/8+N0 Q35Po9PQHn40Guy1JX17n3qQPcHvA2VK1mrAzoI9uqNBnjKeFiv3w1uhJDi3HPjQw/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377118; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=m1edWOCkPeKda3wb9wwi/bS6rkMwg0txGRVV7AwIh9k=; b=Q8+vFEuvZXHKXiybhN3PLHyJu9zj7JCtwNEr5kmoblM8m0iOnXsmBo5Su4GJC0DuyqSa mbPnkbuLh3tO/CNbPjdrSCCptMYeP9PZ65d9KJ7fE33u2lednI/NLGU0H//MbiIvBXaQc WfdqeGYtuTceu2gXjoyksLCLEedabJ4NbontXwVZXerU6PLQC9POAMQFm4DW83qGaykcD ej6WhV/12eysI0+zhPY0a7B9XQDTeAaX1LV3o4qrT4zguMAXSZDUlm3AFFkqrR5Jgf8WF Z8RnhdX4+zGz8wCkw6ihS9MFaBgKEV6f7d2h+yWWTSp0DXM/TEOtCe+nvTHFs12umAA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=amutable.com; spf=pass smtp.mailfrom=amutable.com; dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=K4UH5Mpu; arc=none smtp.remote-ip=209.85.218.53 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C526C606A32D for ; Fri, 4 Dec 2026 09:38:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C526C606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=K4UH5Mpu Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-c50aaad19fbso100790166b.0 for ; Fri, 04 Dec 2026 01:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1796377116; x=1796981916; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=m1edWOCkPeKda3wb9wwi/bS6rkMwg0txGRVV7AwIh9k=; b=K4UH5MpuniBLTHDIOf44TMUg/coPoThdeZpsD0HypyFN8pMfRZ0tQekQmASZSTUXNC VDHv6QhPRELNSr6upt2tiPsP0rBwpp6G38It+E+pSxKQiYp3/eWvctI2o500D6iXsPtu qiTNGvgCPCWelDpT+RoiPbfwgLQWt0MjJqhxqJOGSfaH7bYX5JDsAO6kSBEd4jlUPeQs MyI0LMrtTLex+uWYrQPBq3N/zCuWABiaIynVCfTQF6CsdKhLBkhG4rXWZ0/HzbeAbzc/ c6KgaguEn0dvKVFafJhY/7lKfGYQso1Lw4oK7npxdCzVMut+lh7hrMhaFanBYT2fdQUH 2oHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796377116; x=1796981916; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=m1edWOCkPeKda3wb9wwi/bS6rkMwg0txGRVV7AwIh9k=; b=YCPoRnCy/DCWujg/r58MLzyo8zI7+ff+KAAB8pmWtVRAbLUdR6ZO9Ye+6KCggtjsfU c0GBGw5IrFJY6BFFZMmGEzl5HiuRM7FlDRZCPI+ahYcDfazOCjRgYqkj93nVB1Vx75A5 MFLnSk+3PacGohrJsV0ytyI+nHYYr8sLE6T7gSOLMoHcUnzhdNSCYaD8Mq4aIrF4cXob yC2YJlz8sqjdcCNs94ON67mHABABS/D6hjf236aNfoGGM+ayjfC5FDEAaPHsIWFb8qwT sKdItnZEDVYDxk+JUMUBYDHxiZW8RpVHmv/bl2M62rjnVFX/RAbclcKUlGJ24yc++2CV sbJA== X-Forwarded-Encrypted: i=1; AL+hErEsgVZsTfz2xQqOX75DXP+MIYE/O9i5OU7x643s7aklcPyViii5/JWYAvrJ0WrL8/RZUMifadujLcJqaJ0=@vger.kernel.org X-Gm-Message-State: APuU4Z9arBGp66RtGogKBOpyOp20ESwQxaCl/KwnvmgsSujjmylAcUGH kCCXfjDBFndGgRyEai1kmjxkZGGeuHlBvd5sItBIh29s30YuDUC0I6GG3PegCIbnHWTGiUx5pIz QfFi18AgI X-Gm-Gg: AZFdTZd+mOacagvXQTKQuGRVTUaJSqjwksiAtnvHFTquGvvzhfNvhYWJT58V38k14RG 42QUxaEj5KUyDGeyVXYA9ZVK8TOprVPNkdejhKNTNGBBH9pcT7NlNbqfUN6mE0TP3MWZFx51XoR Isj2fiAS/LSNHqzLVHMAU1Ib/lrH06MG/GnguO81nQ52F6KhQcySfoely100EmwOMupzl9iDMeF O5iFpzxqtrv0voSB4VJsapt35ckbWsIPLzXjsa4gJUW3eWrf8L2TC573j/dXieCmgu3TOilYk12 NDdOR/L6FgU2sC0LohPvSaId8x5BYQSZt93btxIa0kW4qh9/QTO2j8xMj4pNPlWQXLpPQLT1KVm ImxSgQYgxau7h0s4XqKPYYPwobDplvS38zIH5qPgCGjFZY2OR9YYLdRzIFWuZuOuD4vupDVXXxW MUZSN58OQaxNOy1IahkyjebWSZckNW6FXJ39r9N2merAxb782nAfjah28xymUfTJ4Sso6KFs9WW mKu7HmWn92Ow9etXTts0JrnTrEX7AgKftjLtxLnkNKFKv4w7cYweIErG1UyyM3Rw2vNfcGxcirN p57w2PA+RUkrDUz/T7fYhNw2RHsglSuvgJ7mx8nkpQsYOqtWE/gka/EDFjLWd7E4sQ== X-Received: by 2002:a17:907:d1e:b0:c4c:b545:f29d with SMTP id a640c23a62f3a-c5262525393mr95940966b.36.1796377116086; Fri, 04 Dec 2026 01:38:36 -0800 (PST) Received: from [10.0.0.233] (tmo-084-240.customers.d1-online.com. [80.187.84.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b2b91a1sm94078866b.8.2026.12.04.01.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 01:38:35 -0800 (PST) Message-ID: <0592ebcfff28c908d72b8be856d37b46b1a2398d.camel@amutable.com> Subject: Re: [PATCH] kernfs: refresh the inode before changing attributes From: Alexander Mikhalitsyn To: Josef Bacik , Greg Kroah-Hartman , Tejun Heo Cc: Christian Brauner , driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 04 Dec 2026 10:38:34 +0100 In-Reply-To: <20261203-b4-kernfs-setattr-refresh-v1-1-b66a2529427e@bacik.io> References: <20261203-b4-kernfs-setattr-refresh-v1-1-b66a2529427e@bacik.io> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 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 On Thu, 2026-12-03 at 10:51 -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. >=20 > 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. >=20 > Fixes: 3ff195b011d7 ("sysfs: Implement sysfs tagged directory > support.") > Signed-off-by: Josef Bacik LGTM Please feel free to add: Reviewed-by: Alexander Mikhalitsyn Kind regards, Alex > --- > =C2=A0fs/kernfs/inode.c | 29 +++++++++++++++++++++++++++++ > =C2=A01 file changed, 29 insertions(+) >=20 > diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c > index 6630b29d7c078..88d0c0c875184 100644 > --- a/fs/kernfs/inode.c > +++ b/fs/kernfs/inode.c > @@ -107,6 +107,31 @@ int kernfs_setattr(struct kernfs_node *kn, const > struct iattr *iattr) > =C2=A0 return ret; > =C2=A0} > =C2=A0 > +static void kernfs_refresh_inode(struct kernfs_node *kn, struct > inode *inode); > + > +/* Redo what notify_change() decided by the inode as it was cached. > */ > +static int kernfs_setattr_refresh(struct kernfs_node *kn, struct > inode *inode, > + =C2=A0 struct iattr *iattr) > +{ > + unsigned int ia_valid =3D iattr->ia_valid; > + > + kernfs_refresh_inode(kn, inode); > + > + if (ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) { > + iattr->ia_mode =3D inode->i_mode; > + if (ia_valid & ATTR_KILL_SUID) > + iattr->ia_mode &=3D ~S_ISUID; > + if (ia_valid & ATTR_KILL_SGID) > + iattr->ia_mode &=3D ~S_ISGID; > + } > + > + /* may_setattr() would take kernfs_iattr_rwsem again */ > + if ((ia_valid & ATTR_TOUCH) && > + =C2=A0=C2=A0=C2=A0 !inode_owner_or_capable(&nop_mnt_idmap, inode)) > + return generic_permission(&nop_mnt_idmap, inode, > MAY_WRITE); > + return 0; > +} > + > =C2=A0int kernfs_iop_setattr(const struct mnt_idmap *idmap, struct dentry > *dentry, > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct iattr *iattr) > =C2=A0{ > @@ -120,6 +145,10 @@ int kernfs_iop_setattr(const struct mnt_idmap > *idmap, struct dentry *dentry, > =C2=A0 > =C2=A0 root =3D kernfs_root(kn); > =C2=A0 down_write(&root->kernfs_iattr_rwsem); > + error =3D kernfs_setattr_refresh(kn, inode, iattr); > + if (error) > + goto out; > + > =C2=A0 error =3D setattr_prepare(&nop_mnt_idmap, dentry, iattr); > =C2=A0 if (error) > =C2=A0 goto out; > --- > base-commit: b8e026b973764a52b92c0cdc1d3cf96f2abc1058 > change-id: 20261203-b4-kernfs-setattr-refresh-b66a2529427e