Skip to contentSkip to conversation

coda: fix possible data race around sb->s_fs_info access

PATCH New Tuo Li 1 participant 1 message Jun 12, 2023 Coda file system

lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 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.

---
 fs/coda/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/coda/inode.c +1 -1
index d661e6cf17ac..743030ec5ef6 100644
@@ -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;
Signature · 1 line
2.34.1