]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jbd2: gracefully abort instead of panicking on unlocked buffer
authorMilos Nikic <nikic.milos@gmail.com>
Wed, 4 Mar 2026 17:20:15 +0000 (09:20 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 9 Apr 2026 14:46:36 +0000 (10:46 -0400)
In jbd2_journal_get_create_access(), if the caller passes an unlocked
buffer, the code currently triggers a fatal J_ASSERT.

While an unlocked buffer here is a clear API violation and a bug in the
caller, crashing the entire system is an overly severe response. It brings
down the whole machine for a localized filesystem inconsistency.

Replace the J_ASSERT with a WARN_ON_ONCE to capture the offending caller's
stack trace, and return an error (-EINVAL). This allows the journal to
gracefully abort the transaction, protecting data integrity without
causing a kernel panic.

Signed-off-by: Milos Nikic <nikic.milos@gmail.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Link: https://patch.msgid.link/20260304172016.23525-2-nikic.milos@gmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/transaction.c

index dca4b5d8aaaa3e1505b09fab42eb45bb201a8db8..04d17a5f2a82ec8379d2fe81bfa4446a6b58fe54 100644 (file)
@@ -1302,7 +1302,12 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
                goto out;
        }
 
-       J_ASSERT_JH(jh, buffer_locked(jh2bh(jh)));
+       if (WARN_ON_ONCE(!buffer_locked(jh2bh(jh)))) {
+               err = -EINVAL;
+               spin_unlock(&jh->b_state_lock);
+               jbd2_journal_abort(journal, err);
+               goto out;
+       }
 
        if (jh->b_transaction == NULL) {
                /*