]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
jbd2: use a per-journal lock_class_key for jbd2_trans_commit_key
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Wed, 22 Oct 2025 11:11:37 +0000 (20:11 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Jan 2026 09:14:16 +0000 (10:14 +0100)
commit 524c3853831cf4f7e1db579e487c757c3065165c upstream.

syzbot is reporting possibility of deadlock due to sharing lock_class_key
for jbd2_handle across ext4 and ocfs2. But this is a false positive, for
one disk partition can't have two filesystems at the same time.

Reported-by: syzbot+6e493c165d26d6fcbf72@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6e493c165d26d6fcbf72
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot+6e493c165d26d6fcbf72@syzkaller.appspotmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Message-ID: <987110fc-5470-457a-a218-d286a09dd82f@I-love.SAKURA.ne.jp>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/jbd2/journal.c
include/linux/jbd2.h

index c073f5fb98594f404ad57c0eaa39e7c47754a45b..5106ed202f0380aa249b1bf5d075c135e38ae18a 100644 (file)
@@ -1526,7 +1526,6 @@ static journal_t *journal_init_common(struct block_device *bdev,
                        struct block_device *fs_dev,
                        unsigned long long start, int len, int blocksize)
 {
-       static struct lock_class_key jbd2_trans_commit_key;
        journal_t *journal;
        int err;
        int n;
@@ -1535,6 +1534,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
        if (!journal)
                return ERR_PTR(-ENOMEM);
 
+       lockdep_register_key(&journal->jbd2_trans_commit_key);
        journal->j_blocksize = blocksize;
        journal->j_dev = bdev;
        journal->j_fs_dev = fs_dev;
@@ -1565,7 +1565,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
        journal->j_max_batch_time = 15000; /* 15ms */
        atomic_set(&journal->j_reserved_credits, 0);
        lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
-                        &jbd2_trans_commit_key, 0);
+                        &journal->jbd2_trans_commit_key, 0);
 
        /* The journal is marked for error until we succeed with recovery! */
        journal->j_flags = JBD2_ABORT;
@@ -1618,6 +1618,7 @@ err_cleanup:
        kfree(journal->j_wbuf);
        jbd2_journal_destroy_revoke(journal);
        journal_fail_superblock(journal);
+       lockdep_unregister_key(&journal->jbd2_trans_commit_key);
        kfree(journal);
        return ERR_PTR(err);
 }
@@ -2199,6 +2200,7 @@ int jbd2_journal_destroy(journal_t *journal)
                crypto_free_shash(journal->j_chksum_driver);
        kfree(journal->j_fc_wbuf);
        kfree(journal->j_wbuf);
+       lockdep_unregister_key(&journal->jbd2_trans_commit_key);
        kfree(journal);
 
        return err;
index 8aef9bb6ad573518d6f8e0fa76af8530db02b2e8..cf1282f819ea6e3ff0bbec83f715481f576ec4ba 100644 (file)
@@ -1268,6 +1268,12 @@ struct journal_s
         */
        struct lockdep_map      j_trans_commit_map;
 #endif
+       /**
+        * @jbd2_trans_commit_key:
+        *
+        * "struct lock_class_key" for @j_trans_commit_map
+        */
+       struct lock_class_key   jbd2_trans_commit_key;
 
        /**
         * @j_fc_cleanup_callback: