From: Jeongjun Park <aha310510@gmail.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org
Cc: jack@suse.cz, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Jeongjun Park <aha310510@gmail.com>
Subject: [PATCH] fs: prevent data-race due to missing inode_lock when calling vfs_getattr
Date: Mon, 18 Nov 2024 01:37:19 +0900 [thread overview]
Message-ID: <20241117163719.39750-1-aha310510@gmail.com> (raw)
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;
--
next reply other threads:[~2024-11-17 16:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-17 16:37 Jeongjun Park [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241117163719.39750-1-aha310510@gmail.com \
--to=aha310510@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®