From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377118; b=sfICA/+Z4X4NXQDB4Bwl2B9Ix+xgHXmtb+HisK37oK9dQwfpryA4E6xzedKISMn2v428 Fs3K7JhSvs9JIQn9QZanrrmZvLnhfCYDSTHyF7BKQktHcyTy6sXxgAI2aJqh1OrO7W0xy 9gsGYlzA/AGhPH5p8cSTbH31j6jRJpGt4q9llJ83mFj4ep7z2YhBNG/MEkOUqomE7GQ9W 8umG+4GpSpONk1zyvxK06wFhPPV3XTrIMM72EJ//Zxq/Kx3H8OMvJqGTpl6q9TEjfit1a zU47M4GRMfA/GnJQFoKhDTgl/lA841tMET5gwPUfPeX50e1LiiWNcEPUzAiwfI6RTRA== 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=KUHLs2JEgiIiD/tZ5fY+p5EG1d6JhRfGtWZB+TuvOXkDF7BpVjQraG/FovBjc51WlAL0 XCJnHpaX3USKYJX5yfGn4iZEnNu2IqwBA/NNwMGp4up7weDBXEkbsYG3dCMPwrJGOy6YP Nvc+GkYl2hPbeamysvRcix2EuHStyOjtY9YKY1G1tELuG4dBubk2L1ZfiC01FWF+F5HAV qvp/MUo+ZBwnNtoj2BxCjuiq3t/rkpcgr5ZngagLrtpDsPW9itAcMmZVetvwxLw4mcVAc ozPGOch5NTt3EkjH7kserjACuPIze67w7XK8O1NXIcC6NItAsNyi05y2wH1f61BxkcQ== 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=VOLwUp7R; arc=none smtp.remote-ip=209.85.218.43 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 C1C2C606A32C for ; Fri, 4 Dec 2026 09:38:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C1C2C606A32C 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=VOLwUp7R Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c5235be7be9so112369366b.2 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=lists.linux.dev; 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=VOLwUp7R5LNUqe6tKavxJFrBXJLz9NVD7rQLMHE2EfsZI4kQ9CbTXXyhBookxyJLat ycJgXoF7nybKa7RhMzQVDfUhFGehJz3j6zNhcq98h+C0bDUg8cZIE2IEKt9HmrOZp3K/ V+s/RRWQGPF4F+tiy9cNjQb9ZZQZ2tDUIpwrODQ9OCL60Mtdb74mwjq4Euh3I3onMJSV X7LZ1o59K1wUDaBgynLHSjiNufcs3jebLN37hbnRnCZJJUMW6efLJYh0qyKL82rocY6X tEqcA4YYBYFXkjZz4x/l/4mvyh1+IOpyFJbiIme0WnGceGSW/y7yuV1s6novK/0fDQiW 8rbw== 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=m+tpIVQKZl7gH8m3InQpTCUoVFeHz32Lcm2aHkBy+sgFszd6bfCuH57URNdP3Al6en 6gZm9l7WWnBn1gEwmhpHpRFzBW1X5GyIyqXc3HptFXmyRS91vs5tZ0+2NssHIu6iMVva xjgGMIOfIpaX8wT6LUspbOIGYvsyHaKnoglj+5032Ci/ItrnPggl+nkq34PQka6l6k2v nEDt1qub7dVVJv6b+EGGR0MEcUUHzebfX8A/BI16C3Xg0TBGT8RHtDWRiwLBwPkFctW+ oyQlYIsaLFKYJ2w4p8lzFoYaflNPUNiNguVL+MpZiX0wxZfCvc2vm6vCyaImHPw+gM12 3MAA== X-Forwarded-Encrypted: i=1; AL+hErHrx3SybJCmEHyMs/DoW40AE97su1sTfXAOfwjRByEZwolIaIImznio7wHbSLytHfo2NA/v0ZhpmcZU4A==@lists.linux.dev X-Gm-Message-State: APuU4Z/REoNtwae41Of8fuOumCjMjwsWzgrTdOOAC5EAsOKGOxGgTCwm 2lBVAwxSfNsEW1ffrl1HvnxgSV5JmCymZUm/5G06p/hwkUrrNY8D3DrFv7KEPfMfJDYv X-Gm-Gg: AZFdTZdR/ScUNK0792HssmsRVf0FbsEqDNRZrhqPaNMVBqAPH3vYKaoxj8Sg3dJ5D3a Q2ZxxYJKd8qgsUDMKFQze28/z9/Im4SBDsmGey09/swEu4IPcd9zkIwA4kYcdVdYIjWq3UTdLy2 iUzJlbHguBmPYBDOk2/Dc79iyr36jPEOLhe6XjqRSl3fQvsB/+CvddbRywu+DEVrmxLCKaB+zeN FpKA/NotamyvU4iVfiMF/aTLlVnsC1tjZo9nes61KniTlNhpqz+0CZ2m45AB8sl584YO7+WJKtM C2s7d2Yg002tF0EAq72TuqrkEBmspKaeFG3KYV9x5Claz8GdyGuF+bpkWhQGEAoQ0JtF5oxVYZ8 DQfFRCWPd4N2yDtpzc5cfN+Nu+1zv85VewWqKVrAYxjYe0IwcPNCy9B+St/8+4hrPvnEqrrGFen neParWCC1QcwJT6bZHtMPjmPQ5vYQ8c2JCZviYz+f1Swa40TXLvvz21aLFmS5jiPoC3gXtwsows sxAZ/ZxaWvkfSwZmUcVjGNqPUHdtgI7cKX+MPU5AOPixU+m2FP/SkPuvuN3P+wXOtEPZx0rAm0W 1D/3LxrWev1ka1vmUzsZJguPLQarkEzxVsfBs6H/GmKEeJr2JroXXynBPVsa83wW0w== 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: driver-core@lists.linux.dev 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