From: Theodore Ts'o Subject: [PATCH] jbd2: fix theoretical race in jbd2__journal_restart Date: Thu, 20 Jun 2013 12:08:00 -0400 Message-ID: <1371744480-5780-1-git-send-email-tytso@mit.edu> References: <20130620155555.GE28309@thunk.org> Cc: ocfs2-devel@oss.oracle.com, Theodore Ts'o , stable@vger.kernel.org To: Ext4 Developers List Return-path: Received: from li9-11.members.linode.com ([67.18.176.11]:59837 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757937Ab3FTQII (ORCPT ); Thu, 20 Jun 2013 12:08:08 -0400 In-Reply-To: <20130620155555.GE28309@thunk.org> Sender: linux-ext4-owner@vger.kernel.org List-ID: 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" Cc: stable@vger.kernel.org --- [ I plan to carry this in the ext4 tree. ] fs/jbd2/transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 91d62e1..7391456 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -652,10 +652,10 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask) } if (atomic_dec_and_test(&transaction->t_updates)) wake_up(&journal->j_wait_updates); + tid = transaction->t_tid; spin_unlock(&transaction->t_handle_lock); jbd_debug(2, "restarting handle %p\n", handle); - tid = transaction->t_tid; need_to_start = !tid_geq(journal->j_commit_request, tid); read_unlock(&journal->j_state_lock); if (need_to_start) -- 1.7.12.rc0.22.gcdd159b