lkml.org 
[lkml]   [2020]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2] fs: jfs: fix a possible data race in txBegin()
Date
The functions txBegin() and txLazyCommit() can be concurrently executed
in the following call contexts:

Thread1:
jfs_write_inode()
jfs_commit_inode()
txBegin()

Thread2:
jfs_lazycommit()
txLazyCommit()

In txBegin():
tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;

In txLazyCommit():
spin_lock_irq(&log->gclock);
...
tblk->flag |= tblkGC_COMMITTED;
...
spin_unlock_irq(&log->gclock);

A data race can occur for the data structure member "flag".
This data race was found by our concurrency fuzzer.

Thus use the spin lock "gclock" for the resetting of five
data structure members in this function implementation.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
v2:
* Change the description.
Thank Markus Elfring for good advice.

---
fs/jfs/jfs_txnmgr.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index c8ce7f1bc594..a1f124aad2e0 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -415,7 +415,9 @@ tid_t txBegin(struct super_block *sb, int flag)
*
* memset(tblk, 0, sizeof(struct tblock));
*/
+ spin_lock_irq(&log->gclock);
tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;
+ spin_unlock_irq(&log->gclock);

tblk->sb = sb;
++log->logtid;
--
2.17.1
\
 
 \ /
  Last update: 2020-05-05 15:55    [W:0.034 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site