From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: shaggy@kernel.org
Cc: jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] fs: jfs: fix a possible data race in txBegin()
Date: Mon, 4 May 2020 23:34:11 +0800 [thread overview]
Message-ID: <20200504153411.13679-1-baijiaju1990@gmail.com> (raw)
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);
Thus, a data race can occur for tblk->flag.
To fix this data race, the spinlock log->gclock is used in
txBegin().
This data race is found by our concurrency fuzzer.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
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
next reply other threads:[~2020-05-04 15:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 15:34 Jia-Ju Bai [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-05-04 16:15 [PATCH] fs: jfs: fix a possible data race in txBegin() Markus Elfring
2020-05-05 4:10 ` Jia-Ju Bai
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=20200504153411.13679-1-baijiaju1990@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=shaggy@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