Skip to content

Commit 6346966

Browse files
Luis Henriques (SUSE)tytso
authored andcommitted
ext4: fix possible tid_t sequence overflows
In the fast commit code there are a few places where tid_t variables are being compared without taking into account the fact that these sequence numbers may wrap. Fix this issue by using the helper functions tid_gt() and tid_geq(). Signed-off-by: Luis Henriques (SUSE) <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Harshad Shirwadkar <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 2d4d6bd commit 6346966

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/ext4/fast_commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
353353
read_unlock(&sbi->s_journal->j_state_lock);
354354
}
355355
spin_lock(&sbi->s_fc_lock);
356-
if (sbi->s_fc_ineligible_tid < tid)
356+
if (tid_gt(tid, sbi->s_fc_ineligible_tid))
357357
sbi->s_fc_ineligible_tid = tid;
358358
spin_unlock(&sbi->s_fc_lock);
359359
WARN_ON(reason >= EXT4_FC_REASON_MAX);
@@ -1207,7 +1207,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)
12071207
if (ret == -EALREADY) {
12081208
/* There was an ongoing commit, check if we need to restart */
12091209
if (atomic_read(&sbi->s_fc_subtid) <= subtid &&
1210-
commit_tid > journal->j_commit_sequence)
1210+
tid_gt(commit_tid, journal->j_commit_sequence))
12111211
goto restart_fc;
12121212
ext4_fc_update_stats(sb, EXT4_FC_STATUS_SKIPPED, 0, 0,
12131213
commit_tid);
@@ -1282,7 +1282,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
12821282
list_del_init(&iter->i_fc_list);
12831283
ext4_clear_inode_state(&iter->vfs_inode,
12841284
EXT4_STATE_FC_COMMITTING);
1285-
if (iter->i_sync_tid <= tid)
1285+
if (tid_geq(tid, iter->i_sync_tid))
12861286
ext4_fc_reset_inode(&iter->vfs_inode);
12871287
/* Make sure EXT4_STATE_FC_COMMITTING bit is clear */
12881288
smp_mb();
@@ -1313,7 +1313,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
13131313
list_splice_init(&sbi->s_fc_q[FC_Q_STAGING],
13141314
&sbi->s_fc_q[FC_Q_MAIN]);
13151315

1316-
if (tid >= sbi->s_fc_ineligible_tid) {
1316+
if (tid_geq(tid, sbi->s_fc_ineligible_tid)) {
13171317
sbi->s_fc_ineligible_tid = 0;
13181318
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
13191319
}

0 commit comments

Comments
 (0)