Skip to content

Commit

Permalink
jbd2: Fix possible overflow in jbd2_log_space_left()
Browse files Browse the repository at this point in the history
When number of free space in the journal is very low, the arithmetic in
jbd2_log_space_left() could underflow resulting in very high number of
free blocks and thus triggering assertion failure in transaction commit
code complaining there's not enough space in the journal:

J_ASSERT(journal->j_free > 1);

Properly check for the low number of free blocks.

CC: stable@vger.kernel.org
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20191105164437.32602-1-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Jan Kara authored and Theodore Ts'o committed Nov 5, 2019
1 parent 4f5cafb commit add3efd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/linux/jbd2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ static inline int jbd2_space_needed(journal_t *journal)
static inline unsigned long jbd2_log_space_left(journal_t *journal)
{
/* Allow for rounding errors */
unsigned long free = journal->j_free - 32;
long free = journal->j_free - 32;

if (journal->j_committing_transaction) {
unsigned long committing = atomic_read(&journal->
Expand All @@ -1591,7 +1591,7 @@ static inline unsigned long jbd2_log_space_left(journal_t *journal)
/* Transaction + control blocks */
free -= committing + (committing >> JBD2_CONTROL_BLOCKS_SHIFT);
}
return free;
return max_t(long, free, 0);
}

/*
Expand Down

0 comments on commit add3efd

Please sign in to comment.