public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coda: fix possible data race around sb->s_fs_info access
@ 2023-06-12  7:21 Tuo Li
  0 siblings, 0 replies; only message in thread
From: Tuo Li @ 2023-06-12  7:21 UTC (permalink / raw)
  To: jaharkes; +Cc: coda, codalist, linux-kernel, baijiaju1990, Tuo Li, BassCheck

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-12  7:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-12  7:21 [PATCH] coda: fix possible data race around sb->s_fs_info access Tuo Li

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