All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.14 01/11] jbd2: make sure jh have b_transaction set in refile/unfile_buffer
@ 2020-08-24 16:39 Sasha Levin
  2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 02/11] ext4: don't BUG on inconsistent journal feature Sasha Levin
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Sasha Levin @ 2020-08-24 16:39 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Lukas Czerner, Jan Kara, Theodore Ts'o, Sasha Levin, linux-ext4

From: Lukas Czerner <lczerner@redhat.com>

[ Upstream commit 24dc9864914eb5813173cfa53313fcd02e4aea7d ]

Callers of __jbd2_journal_unfile_buffer() and
__jbd2_journal_refile_buffer() assume that the b_transaction is set. In
fact if it's not, we can end up with journal_head refcounting errors
leading to crash much later that might be very hard to track down. Add
asserts to make sure that is the case.

We also make sure that b_next_transaction is NULL in
__jbd2_journal_unfile_buffer() since the callers expect that as well and
we should not get into that stage in this state anyway, leading to
problems later on if we do.

Tested with fstests.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20200617092549.6712-1-lczerner@redhat.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/jbd2/transaction.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index a355ca418e788..b4bde0ae10948 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -1914,6 +1914,9 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
  */
 static void __jbd2_journal_unfile_buffer(struct journal_head *jh)
 {
+	J_ASSERT_JH(jh, jh->b_transaction != NULL);
+	J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
+
 	__jbd2_journal_temp_unlink_buffer(jh);
 	jh->b_transaction = NULL;
 	jbd2_journal_put_journal_head(jh);
@@ -2461,6 +2464,13 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
 
 	was_dirty = test_clear_buffer_jbddirty(bh);
 	__jbd2_journal_temp_unlink_buffer(jh);
+
+	/*
+	 * b_transaction must be set, otherwise the new b_transaction won't
+	 * be holding jh reference
+	 */
+	J_ASSERT_JH(jh, jh->b_transaction != NULL);
+
 	/*
 	 * We set b_transaction here because b_next_transaction will inherit
 	 * our jh reference and thus __jbd2_journal_file_buffer() must not
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-08-24 17:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 16:39 [PATCH AUTOSEL 4.14 01/11] jbd2: make sure jh have b_transaction set in refile/unfile_buffer Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 02/11] ext4: don't BUG on inconsistent journal feature Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 03/11] jbd2: abort journal if free a async write error metadata buffer Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 04/11] fs: prevent BUG_ON in submit_bh_wbc() Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 05/11] spi: stm32: fix stm32_spi_prepare_mbr in case of odd clk_rate Sasha Levin
2020-08-24 16:39   ` Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 06/11] s390/cio: add cond_resched() in the slow_eval_known_fn() loop Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 07/11] scsi: ufs: Fix possible infinite loop in ufshcd_hold Sasha Levin
2020-08-24 16:39   ` Sasha Levin
2020-08-24 16:39   ` Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 08/11] scsi: ufs: Improve interrupt handling for shared interrupts Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 09/11] scsi: ufs: Clean up completed request without interrupt notification Sasha Levin
2020-08-24 16:39   ` Sasha Levin
2020-08-24 16:39   ` Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 10/11] net: gianfar: Add of_node_put() before goto statement Sasha Levin
2020-08-24 16:39 ` [PATCH AUTOSEL 4.14 11/11] powerpc/perf: Fix soft lockups due to missed interrupt accounting Sasha Levin
2020-08-24 16:39   ` Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.