public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: prevent data-race due to missing inode_lock when calling vfs_getattr
@ 2024-11-17 16:37 Jeongjun Park
  2024-11-17 16:55 ` Al Viro
  2024-11-17 22:52 ` Dave Chinner
  0 siblings, 2 replies; 9+ messages in thread
From: Jeongjun Park @ 2024-11-17 16:37 UTC (permalink / raw)
  To: viro, brauner; +Cc: jack, linux-fsdevel, linux-kernel, stable, Jeongjun Park

Many filesystems lock inodes before calling vfs_getattr, so there is no
data-race for inodes. However, some functions in fs/stat.c that call
vfs_getattr do not lock inodes, so the data-race occurs.

Therefore, we need to apply a patch to remove the long-standing data-race
for inodes in some functions that do not lock inodes.

Cc: <stable@vger.kernel.org>
Fixes: da9aa5d96bfe ("fs: remove vfs_statx_fd")
Fixes: 0ef625bba6fb ("vfs: support statx(..., NULL, AT_EMPTY_PATH, ...)")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 fs/stat.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/stat.c b/fs/stat.c
index 41e598376d7e..da532b611aa3 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -220,13 +220,21 @@ EXPORT_SYMBOL(vfs_getattr);
  */
 int vfs_fstat(int fd, struct kstat *stat)
 {
+	const struct path *path;
+	struct inode *inode;
 	struct fd f;
 	int error;
 
 	f = fdget_raw(fd);
 	if (!fd_file(f))
 		return -EBADF;
-	error = vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
+
+	path = &fd_file(f)->f_path;
+	inode = d_backing_inode(path->dentry);
+
+	inode_lock_shared(inode);
+	error = vfs_getattr(path, stat, STATX_BASIC_STATS, 0);
+	inode_unlock_shared(inode);
 	fdput(f);
 	return error;
 }
@@ -248,7 +256,11 @@ int getname_statx_lookup_flags(int flags)
 static int vfs_statx_path(struct path *path, int flags, struct kstat *stat,
 			  u32 request_mask)
 {
+	struct inode *inode = d_backing_inode(path->dentry);
+
+	inode_lock_shared(inode);
 	int error = vfs_getattr(path, stat, request_mask, flags);
+	inode_unlock_shared(inode);
 
 	if (request_mask & STATX_MNT_ID_UNIQUE) {
 		stat->mnt_id = real_mount(path->mnt)->mnt_id_unique;
--

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-11-20  9:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-17 16:37 [PATCH] fs: prevent data-race due to missing inode_lock when calling vfs_getattr Jeongjun Park
2024-11-17 16:55 ` Al Viro
2024-11-18  6:00   ` Jeongjun Park
2024-11-18  7:03     ` Al Viro
2024-11-20  1:44       ` Mateusz Guzik
2024-11-20  2:08         ` Al Viro
2024-11-20  2:29           ` Mateusz Guzik
2024-11-20  9:19         ` Christian Brauner
2024-11-17 22:52 ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox