All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Lukas Czerner <lczerner@redhat.com>, Jan Kara <jack@suse.cz>,
	Theodore Ts'o <tytso@mit.edu>, Sasha Levin <sashal@kernel.org>,
	linux-ext4@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 01/21] jbd2: make sure jh have b_transaction set in refile/unfile_buffer
Date: Mon, 24 Aug 2020 12:38:25 -0400	[thread overview]
Message-ID: <20200824163845.606933-1-sashal@kernel.org> (raw)

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 43693b6797105..5a0de78a5d71a 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -1915,6 +1915,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);
@@ -2462,6 +2465,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


             reply	other threads:[~2020-08-24 16:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 16:38 Sasha Levin [this message]
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 02/21] ext4: don't BUG on inconsistent journal feature Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 03/21] ext4: handle read only external journal device Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 04/21] jbd2: abort journal if free a async write error metadata buffer Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 05/21] ext4: handle option set by mount flags correctly Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 06/21] ext4: handle error of ext4_setup_system_zone() on remount Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 07/21] ext4: correctly restore system zone info when remount fails Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 08/21] fs: prevent BUG_ON in submit_bh_wbc() Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 09/21] spi: stm32: fix stm32_spi_prepare_mbr in case of odd clk_rate Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 10/21] s390/cio: add cond_resched() in the slow_eval_known_fn() loop Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 11/21] ASoC: wm8994: Avoid attempts to read unreadable registers Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 12/21] scsi: fcoe: Fix I/O path allocation Sasha Levin
2020-08-24 16:38   ` [Intel-wired-lan] " Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 13/21] scsi: ufs: Fix possible infinite loop in ufshcd_hold Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 14/21] scsi: ufs: Improve interrupt handling for shared interrupts Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 15/21] scsi: ufs: Clean up completed request without interrupt notification Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38   ` Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 16/21] scsi: qla2xxx: Check if FW supports MQ before enabling Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 17/21] scsi: qla2xxx: Fix null pointer access during disconnect from subsystem Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 18/21] Revert "scsi: qla2xxx: Fix crash on qla2x00_mailbox_command" Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 19/21] macvlan: validate setting of multiple remote source MAC addresses Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 20/21] net: gianfar: Add of_node_put() before goto statement Sasha Levin
2020-08-24 16:38 ` [PATCH AUTOSEL 4.19 21/21] powerpc/perf: Fix soft lockups due to missed interrupt accounting Sasha Levin
2020-08-24 16:38   ` Sasha Levin

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=20200824163845.606933-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=jack@suse.cz \
    --cc=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 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.