From: Tuo Li <islituo@gmail.com>
To: jaharkes@cs.cmu.edu
Cc: coda@cs.cmu.edu, codalist@coda.cs.cmu.edu,
linux-kernel@vger.kernel.org, baijiaju1990@outlook.com,
Tuo Li <islituo@gmail.com>, BassCheck <bass@buaa.edu.cn>
Subject: [PATCH] coda: fix possible data race around sb->s_fs_info access
Date: Mon, 12 Jun 2023 15:21:01 +0800 [thread overview]
Message-ID: <20230612072101.2923400-1-islituo@gmail.com> (raw)
The struct field s_fs_info is often protected by the lock vc_mutex when is
accessed. Here is an example in coda_put_super():
mutex_lock(&vcp->vc_mutex);
vcp->vc_sb = NULL;
sb->s_fs_info = NULL;
mutex_unlock(&vcp->vc_mutex);
However, sb->s_fs_info is accessed after the lock vc->vc_mutex is unlocked
in coda_fill_super()
vc->vc_sb = sb;
mutex_unlock(&vc->vc_mutex);
sb->s_fs_info = vc;
And thus can cause a data race when another thread access sb->s_fs_info
concurrently.
To fix this possible data race, the instruction to unlock vc->vc_mutex is
moved in front of the access to sb->s_fs_info.
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
fs/coda/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index d661e6cf17ac..743030ec5ef6 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -179,9 +179,9 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
}
vc->vc_sb = sb;
+ sb->s_fs_info = vc;
mutex_unlock(&vc->vc_mutex);
- sb->s_fs_info = vc;
sb->s_flags |= SB_NOATIME;
sb->s_blocksize = 4096; /* XXXXX what do we put here?? */
sb->s_blocksize_bits = 12;
--
2.34.1
reply other threads:[~2023-06-12 7:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230612072101.2923400-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=baijiaju1990@outlook.com \
--cc=bass@buaa.edu.cn \
--cc=coda@cs.cmu.edu \
--cc=codalist@coda.cs.cmu.edu \
--cc=jaharkes@cs.cmu.edu \
--cc=linux-kernel@vger.kernel.org \
/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