[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20230612072101.2923400-1-islituo@gmail.com>
Date: Mon, 12 Jun 2023 15:21:01 +0800
From: Tuo Li <islituo@...il.com>
To: jaharkes@...cmu.edu
Cc: coda@...cmu.edu, codalist@...a.cs.cmu.edu,
linux-kernel@...r.kernel.org, baijiaju1990@...look.com,
Tuo Li <islituo@...il.com>, BassCheck <bass@...a.edu.cn>
Subject: [PATCH] coda: fix possible data race around sb->s_fs_info access
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@...a.edu.cn>
Signed-off-by: Tuo Li <islituo@...il.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
Powered by blists - more mailing lists