]> git.hungrycats.org Git - linux/commitdiff
ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible()
authorLuis Henriques (SUSE) <luis.henriques@linux.dev>
Wed, 24 Jul 2024 16:11:18 +0000 (17:11 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:00:51 +0000 (12:00 +0200)
commit ebc4b2c1ac92fc0f8bf3f5a9c285a871d5084a6b upstream.

Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a
valid value for transaction IDs, which is incorrect.

Furthermore, the sbi->s_fc_ineligible_tid handling also makes the same
assumption by being initialised to '0'.  Fortunately, the sb flag
EXT4_MF_FC_INELIGIBLE can be used to check whether sbi->s_fc_ineligible_tid
has been previously set instead of comparing it with '0'.

Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240724161119.13448-5-luis.henriques@linux.dev
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/fast_commit.c

index 3926a05eceeed1cf5ef23b4e5acdf8769906020b..6f4c97bdb2d806379c56e48916bacbdf18a43e32 100644 (file)
@@ -339,22 +339,29 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        tid_t tid;
+       bool has_transaction = true;
+       bool is_ineligible;
 
        if (ext4_fc_disabled(sb))
                return;
 
-       ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
        if (handle && !IS_ERR(handle))
                tid = handle->h_transaction->t_tid;
        else {
                read_lock(&sbi->s_journal->j_state_lock);
-               tid = sbi->s_journal->j_running_transaction ?
-                               sbi->s_journal->j_running_transaction->t_tid : 0;
+               if (sbi->s_journal->j_running_transaction)
+                       tid = sbi->s_journal->j_running_transaction->t_tid;
+               else
+                       has_transaction = false;
                read_unlock(&sbi->s_journal->j_state_lock);
        }
        spin_lock(&sbi->s_fc_lock);
-       if (tid_gt(tid, sbi->s_fc_ineligible_tid))
+       is_ineligible = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
+       if (has_transaction &&
+           (!is_ineligible ||
+            (is_ineligible && tid_gt(tid, sbi->s_fc_ineligible_tid))))
                sbi->s_fc_ineligible_tid = tid;
+       ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
        spin_unlock(&sbi->s_fc_lock);
        WARN_ON(reason >= EXT4_FC_REASON_MAX);
        sbi->s_fc_stats.fc_ineligible_reason_count[reason]++;