From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794844510; b=t6hePCGrjAxYGDbRWhEZckgZmUfj1WTC/ovhhhY5H+2929frXxebby2yDAX8K9cjzFo5 D0vCqbMLHEs0HOJLZgCnVKcJZMDqmiMQ5+oL0Btv6NuucHkXTDeNu8JmO+jPn+3MA0U/f lkEon1rAHzcMS563TYB84nEI1GVN4kdkuB/p/tU7YYSK077L93UkevgmSOroTKYeJ7sSX ot76NbBQB14I6H7adE/alq+7zXUVlB9legdPbjP7qofb2v2yQzno+12IceNy6ksBswIrS wOgHEGUHpPNB1DDj91SFgdo+CunXkzVCyHFJLOJh/9KZ5COxPvhPSD0OAqWKtBWGK7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794844510; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Type:Date:Message-Id:Subject:From:To:Cc:X-Mailer: References:In-Reply-To; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=xIP6+AHC4FHpuGcDzfP8zL499evuqleAeFyl1P+YZjXQdpYjtRq/3J975aBt+1YZwpWm VhvTJr/fJ4YcKlK1OkxgGK1sq0HCL+hfUHfcIZf67DQMxiHgruxpUIf1o9VCXwB6+wLBv 4G0XD8FGkTMHx0JOiyAsvoqWXjv6aF7LmsLP0rLqJ3WmOnzQJ6vluVTtIsQR45LktEhQ1 EzpaKe3sMRkZG1q+4Aq4v/A27yoMWefr1MKebTugpM7dcDCL75bw8+BbJnzxBfTZtJxoU 5GZCkyGq8hMtikJC86yoe0cVXlaZ6v+vpCveoQh9wJ/pD8rUWtDfTC6M9tzr8NT+eRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="pzw1LYv/"; arc=none smtp.remote-ip=209.85.128.54 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 0C4F2606A31C for ; Mon, 16 Nov 2026 15:55:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0C4F2606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pzw1LYv/ Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4bb55cda775so16465975e9.0 for ; Mon, 16 Nov 2026 07:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794844507; x=1795449307; darn=vger.kernel.org; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=pzw1LYv/GrIlyi119CS5O4dqTEojMh2PPNb0YLcVL7AgRpRPj91hUHUDLzwGHiIkuC 5ghAwsq0A9srRmVkNB8Ix2AZMHzK2FSmwfF1fpVV6wSxAgjHZbG1qbtI/8JNO2HgW+r3 XgDVOXvb5VVxNKCsylQTXVTZZnpIc/RC1U9X4IdocD0LsekYcooCdMYN+Ye/PIugulrR bsLdCqNRm/HCjdSVlog5UWaUqIdJSeiekv7v0ydQZt8YByVGiL3lGc9Lkhi/TNtQ+1ll hw9b6NezzwKImWenA2JKyQoRtyOhZw4ZVaZluabORLOPZCH4hh4orZFsxIpsVOaBSg97 1eRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794844508; x=1795449308; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=AKi6CuN6JeyOyCS+sorDRWK/ZyODM4NnptMDSxJ0vJDtIBiwAs5O7n3Oa6ceFe+LDF ycQDZ+Pad9p+e2dNNBkDQI3VsSQA1jEHWkaL9apFqj+1pIGDWfwTwVUK5okpPm37IiYs eOsW2jHgxManpuLO7Tzft7Xzru4Qf73gaedWPXvQd4GoLwvAzpy3jKshSNryOPh9IKV7 74Use9jaCm0pmdpS7z6dTAO3AD9+d5usWqepWONUj6zmO2qsDrXxTZRn+f80nNiPK/r4 zfdc2gOY2tUQkj1MP73ThaCwLoAz2lmh+ebLaCIy7tldRS8nA+gEXQ/gyzQbTuMEJBfk 3eZQ== X-Forwarded-Encrypted: i=1; AL+hErGDoNn4ac8pXx07T25B3jS4dxRJo2xDGV2mHS+eaaqRCJUbR0FNvt7xdmRXe/APpXR2sc/nFMRGpe0=@vger.kernel.org X-Gm-Message-State: APuU4Z9tPI9EOs0JClBIL1truMsbhK9IH+7Y4CI5pNNZsnZ1JuHsnhe7 /FydcPb27OMSSeC2vMMfNIuRxmf/hfeu5eNLG61wQK3D/anPii7ZBmUo X-Gm-Gg: AYBFou2JYd+t7GpZKtLN6psgd0Te0W5TvV7957+RioFjP8hR4ziNhVnLYdOb0gNOwxm Q1YkUVr0mLqHlgT6QuuZd+TJJzxoQGT4vrxHBPxt+sTNKegDY1TrYQfaPXCDkAfIUYHnuLg+Wno ftVhKZFhbpPkV0+rgdIEe6j6e7uza41n/lgzQG601iinr1QC1DBvYHyxlcc1BDvk8/ECXpv5w2Q 6gPIhUW3+Y1+L3eNDFLUEFT2Lg8OkE5HO0GU4qRE572mxczS9vqTQiKrcOTPNoQ4CBmgnW1zEI0 MM4WJL40YqjjT4LPOYtQBHTl8CzMCyOsj1tXwNdUZ2YNEGrJvyuQdjYK17qzJUFmR3yF6GHaQie +yGdMJP9f/BlQBvgNSnUyiQqEvBjh4lFYjwbVtpMF/5yzrhK2EXFLEQZV1Zzi+DrAFGqWpNnzly de/9hmM8mJW4ooGM2FrF+XmLO5zhWPnpp1oLNDkddenZTIM+fc+h06eLjdAjLhHMcjnKE+HvbJg wi0zNdR1mMhLkpKj0Ohsb5jXJRQTgk2FyE5t+eIu58cDhf4JKoefj5okzl5DUyqFQItD36HaJK3 0U81JNtfW3eLfIRNIJhBQlkiYg== X-Received: by 2002:a05:600c:1906:b0:4a1:c6f5:2450 with SMTP id 5b1f17b1804b1-4bb55ac2a34mr244783135e9.17.1794844507334; Mon, 16 Nov 2026 07:55:07 -0800 (PST) Received: from localhost ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb55ae501bsm321476945e9.10.2026.11.16.07.55.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2026 07:55:05 -0800 (PST) X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: multipart/signed; boundary=f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d; micalg=pgp-sha512; protocol="application/pgp-signature" Date: Mon, 16 Nov 2026 16:55:02 +0100 Message-Id: Subject: Re: [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers From: "koraynilay" To: "Amir Goldstein" , "koraynilay" Cc: "David Sterba" , "Namjae Jeon" , "Sungjong Seo" , "Alexander Viro" , "Christian Brauner" , "Trond Myklebust" , "Anna Schumaker" , "Chuck Lever" , "Jeff Layton" , "Konstantin Komarov" , "Paulo Alcantara" , "Chris Mason" , "Yuezhang Mo" , "Jan Kara" , "NeilBrown" , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Ronnie Sahlberg" , "Shyam Prasad N" , "Bharath SM" , "Sergey Senozhatsky" , "ChenXiaoSong" , "Darrick J . Wong" , "Sean Smith" , "Andrey Albershteyn" , "Pedro Falcato" , =?utf-8?q?Pali_Roh=C3=A1r?= , , , , , , , , X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261115180343.576773-1-koray.fra@gmail.com> <20261115180343.576773-7-koray.fra@gmail.com> In-Reply-To: --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Mon Nov 16, 2026 at 2:52 PM CET, Amir Goldstein wrote: > On Sun, Nov 15, 2026 at 7:04=E2=80=AFPM koraynilay = wrote: >> >> Currently there is no way for a caller to invoke vfs_fileattr_set() >> while holding an inode lock without having the kernel go into deadlock. >> >> Fix this by moving the vfs_fileattr_set() logic into >> __vfs_fileattr_set_locked() and making vfs_fileattr_set() a simple >> wrapper that only handles the inode lock. >> >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7 >> Signed-off-by: koraynilay >> --- >> fs/file_attr.c | 139 +++++++++++++++++++++++---------------- >> include/linux/fileattr.h | 2 + >> 2 files changed, 86 insertions(+), 55 deletions(-) >> >> diff --git a/fs/file_attr.c b/fs/file_attr.c >> index 12610fb6a751..063c81fbfa6a 100644 >> --- a/fs/file_attr.c >> +++ b/fs/file_attr.c >> @@ -288,6 +288,89 @@ static int fileattr_set_prepare(struct inode *inode= , >> return 0; >> } >> >> +/** >> + * __vfs_fileattr_set_locked - change miscellaneous file attributes whi= le >> + * holding the inode lock >> + * >> + * @idmap: idmap of the mount >> + * @dentry: the object to change >> + * @fa: fileattr pointer >> + * >> + * Same as vfs_fileattr_set(), but caller must hold the inode lock. >> + * >> + * Return: 0 on success, or a negative error on failure. >> + */ >> +int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct den= try *dentry, >> + struct file_kattr *fa) >> +{ >> + struct inode *inode =3D d_inode(dentry); >> + struct file_kattr old_ma =3D {}; >> + int err; >> + >> + if (!inode->i_op->fileattr_set) >> + return -ENOIOCTLCMD; >> + >> + if (!inode_owner_or_capable(idmap, inode)) >> + return -EPERM; >> + >> + err =3D vfs_fileattr_get(dentry, &old_ma); >> + if (err) >> + return err; >> + >> + /* initialize missing bits from old_ma */ >> + if (fa->flags_valid) { >> + /* FS_IOC_SETFLAGS */ >> + fa->fsx_xflags |=3D (old_ma.fsx_xflags & FS_XFLAGS_MASK)= & >> + ~FS_XFLAG_COMMON; >> + fa->fsx_extsize =3D old_ma.fsx_extsize; >> + fa->fsx_nextents =3D old_ma.fsx_nextents; >> + fa->fsx_projid =3D old_ma.fsx_projid; >> + fa->fsx_cowextsize =3D old_ma.fsx_cowextsize; >> + fa->fsx_ptime =3D old_ma.fsx_ptime; >> + } else { >> + /* >> + * Preserve unmasked xflags when running file_setattr() >> + * with a mask, which doesn't need a read-modify-write >> + * so these attributes would be set to 0. >> + * >> + * With FS_IOC_FSSETXATTR or mask =3D=3D 0 (legacy mode) >> + * this is not needed as userspace does >> + * read-modify-write already. >> + */ >> + if (fa->fsx_xflags_mask) { >> + fa->fsx_xflags |=3D old_ma.fsx_xflags & >> + ~fa->fsx_xflags_mask; >> + fileattr_fill_xflags(fa, fa->fsx_xflags & >> + ~FS_XFLAG_RDONLY_MASK); >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_EXTSIZE)) >> + fa->fsx_extsize =3D old_ma.fsx_extsize; >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PROJID)) >> + fa->fsx_projid =3D old_ma.fsx_projid; >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_COWEXTSIZE)= ) >> + fa->fsx_cowextsize =3D old_ma.fsx_cowext= size; >> + } >> + fa->flags |=3D old_ma.flags & ~FS_COMMON_FL; >> + >> + /* xflags not present in fsxattr */ >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME)) >> + fa->fsx_ptime =3D old_ma.fsx_ptime; >> + } >> + >> + err =3D fileattr_set_prepare(inode, &old_ma, fa); >> + if (err) >> + return err; >> + err =3D security_inode_file_setattr(dentry, fa); >> + if (err) >> + return err; >> + err =3D inode->i_op->fileattr_set(idmap, dentry, fa); >> + if (err) >> + return err; >> + fsnotify_xattr(dentry); >> + >> + return 0; >> +} >> +EXPORT_SYMBOL(__vfs_fileattr_set_locked); >> + >> /** >> * vfs_fileattr_set - change miscellaneous file attributes >> * @idmap: idmap of the mount >> @@ -308,7 +391,6 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, = struct dentry *dentry, >> struct file_kattr *fa) >> { >> struct inode *inode =3D d_inode(dentry); >> - struct file_kattr old_ma =3D {}; >> int err; >> >> if (!inode->i_op->fileattr_set) >> @@ -318,60 +400,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap,= struct dentry *dentry, >> return -EPERM; >> >> inode_lock(inode); >> - err =3D vfs_fileattr_get(dentry, &old_ma); >> - if (!err) { >> - /* initialize missing bits from old_ma */ >> - if (fa->flags_valid) { >> - /* FS_IOC_SETFLAGS */ >> - fa->fsx_xflags |=3D (old_ma.fsx_xflags & FS_XFLA= GS_MASK) & >> - ~FS_XFLAG_COMMON; >> - fa->fsx_extsize =3D old_ma.fsx_extsize; >> - fa->fsx_nextents =3D old_ma.fsx_nextents; >> - fa->fsx_projid =3D old_ma.fsx_projid; >> - fa->fsx_cowextsize =3D old_ma.fsx_cowextsize; >> - fa->fsx_ptime =3D old_ma.fsx_ptime; >> - } else { >> - /* >> - * Preserve unmasked xflags when running file_se= tattr() >> - * with a mask, which doesn't need a read-modify= -write >> - * so these attributes would be set to 0. >> - * >> - * With FS_IOC_FSSETXATTR or mask =3D=3D 0 (lega= cy mode) >> - * this is not needed as userspace does >> - * read-modify-write already. >> - */ >> - if (fa->fsx_xflags_mask) { >> - fa->fsx_xflags |=3D old_ma.fsx_xflags & >> - ~fa->fsx_xflags_mask; >> - fileattr_fill_xflags(fa, fa->fsx_xflags = & >> - ~FS_XFLAG_RDONLY_MA= SK); >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_EXT= SIZE)) >> - fa->fsx_extsize =3D old_ma.fsx_e= xtsize; >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PRO= JID)) >> - fa->fsx_projid =3D old_ma.fsx_pr= ojid; >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_COW= EXTSIZE)) >> - fa->fsx_cowextsize =3D old_ma.fs= x_cowextsize; >> - } >> - fa->flags |=3D old_ma.flags & ~FS_COMMON_FL; >> - >> - /* xflags not present in fsxattr */ >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME)) >> - fa->fsx_ptime =3D old_ma.fsx_ptime; >> - } >> - >> - err =3D fileattr_set_prepare(inode, &old_ma, fa); >> - if (err) >> - goto out; >> - err =3D security_inode_file_setattr(dentry, fa); >> - if (err) >> - goto out; >> - err =3D inode->i_op->fileattr_set(idmap, dentry, fa); >> - if (err) >> - goto out; >> - fsnotify_xattr(dentry); >> - } >> - >> -out: >> + err =3D __vfs_fileattr_set_locked(idmap, dentry, fa); >> inode_unlock(inode); >> return err; >> } >> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >> index ba7ed3b387d8..7ff62ee27e58 100644 >> --- a/include/linux/fileattr.h >> +++ b/include/linux/fileattr.h >> @@ -97,6 +97,8 @@ static inline bool fileattr_has_fsx(const struct file_= kattr *fa) >> int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa); >> int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dent= ry, >> struct file_kattr *fa); >> +int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct den= try *dentry, >> + struct file_kattr *fa); > > There is no reason for __ prefix here and I think it should be discourage= d for > global scope if possible. Ah ok, I copied what had been done for __vfs_setxattr_locked() / vfs_setxattr() and __vfs_removexattr_locked() / vfs_removexattr(), but I agree that __ makes it more "internal", I'll change it for v5. Thanks, koraynilay > Thanks, > Amir. --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCavsnVgAKCRDmj22qf5IG XC40APwLpgC2qCi2ygC417CAeeBgnvIyXQNVw3WOnFMBGg8tUQEAsuqI0c//BtxD +1WkW5Y6mUri16pC/bv/iBr7lSbFFAs= =Rkz6 -----END PGP SIGNATURE----- --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d--