jbd2: fix theoretical race in jbd2__journal_restart
authorTheodore Ts'o <tytso@mit.edu>
Mon, 1 Jul 2013 12:12:40 +0000 (08:12 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 27 Jul 2013 04:34:25 +0000 (05:34 +0100)
commit29b25876eb2252e5b6ea0752e1e2103a83072af2
tree7985900256602172123377977da07b74ebffe31a
parent78d07e4aa54372ad2240273e0969ebf7f44fc3c0
jbd2: fix theoretical race in jbd2__journal_restart

commit 39c04153fda8c32e85b51c96eb5511a326ad7609 upstream.

Once we decrement transaction->t_updates, if this is the last handle
holding the transaction from closing, and once we release the
t_handle_lock spinlock, it's possible for the transaction to commit
and be released.  In practice with normal kernels, this probably won't
happen, since the commit happens in a separate kernel thread and it's
unlikely this could all happen within the space of a few CPU cycles.

On the other hand, with a real-time kernel, this could potentially
happen, so save the tid found in transaction->t_tid before we release
t_handle_lock.  It would require an insane configuration, such as one
where the jbd2 thread was set to a very high real-time priority,
perhaps because a high priority real-time thread is trying to read or
write to a file system.  But some people who use real-time kernels
have been known to do insane things, including controlling
laser-wielding industrial robots.  :-)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/jbd2/transaction.c