Skip to content

Commit c0a2ad9

Browse files
OGAWAHirofumitytso
authored andcommitted
jbd2: fix FS corruption possibility in jbd2_journal_destroy() on umount path
On umount path, jbd2_journal_destroy() writes latest transaction ID (->j_tail_sequence) to be used at next mount. The bug is that ->j_tail_sequence is not holding latest transaction ID in some cases. So, at next mount, there is chance to conflict with remaining (not overwritten yet) transactions. mount (id=10) write transaction (id=11) write transaction (id=12) umount (id=10) <= the bug doesn't write latest ID mount (id=10) write transaction (id=11) crash mount [recovery process] transaction (id=11) transaction (id=12) <= valid transaction ID, but old commit must not replay Like above, this bug become the cause of recovery failure, or FS corruption. So why ->j_tail_sequence doesn't point latest ID? Because if checkpoint transactions was reclaimed by memory pressure (i.e. bdev_try_to_free_page()), then ->j_tail_sequence is not updated. (And another case is, __jbd2_journal_clean_checkpoint_list() is called with empty transaction.) So in above cases, ->j_tail_sequence is not pointing latest transaction ID at umount path. Plus, REQ_FLUSH for checkpoint is not done too. So, to fix this problem with minimum changes, this patch updates ->j_tail_sequence, and issue REQ_FLUSH. (With more complex changes, some optimizations would be possible to avoid unnecessary REQ_FLUSH for example though.) BTW, journal->j_tail_sequence = ++journal->j_transaction_sequence; Increment of ->j_transaction_sequence seems to be unnecessary, but ext3 does this. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent 2d90c16 commit c0a2ad9

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎fs/jbd2/journal.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,11 +1430,12 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
14301430
/**
14311431
* jbd2_mark_journal_empty() - Mark on disk journal as empty.
14321432
* @journal: The journal to update.
1433+
* @write_op: With which operation should we write the journal sb
14331434
*
14341435
* Update a journal's dynamic superblock fields to show that journal is empty.
14351436
* Write updated superblock to disk waiting for IO to complete.
14361437
*/
1437-
static void jbd2_mark_journal_empty(journal_t *journal)
1438+
static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
14381439
{
14391440
journal_superblock_t *sb = journal->j_superblock;
14401441

@@ -1452,7 +1453,7 @@ static void jbd2_mark_journal_empty(journal_t *journal)
14521453
sb->s_start = cpu_to_be32(0);
14531454
read_unlock(&journal->j_state_lock);
14541455

1455-
jbd2_write_superblock(journal, WRITE_FUA);
1456+
jbd2_write_superblock(journal, write_op);
14561457

14571458
/* Log is no longer empty */
14581459
write_lock(&journal->j_state_lock);
@@ -1738,7 +1739,13 @@ int jbd2_journal_destroy(journal_t *journal)
17381739
if (journal->j_sb_buffer) {
17391740
if (!is_journal_aborted(journal)) {
17401741
mutex_lock(&journal->j_checkpoint_mutex);
1741-
jbd2_mark_journal_empty(journal);
1742+
1743+
write_lock(&journal->j_state_lock);
1744+
journal->j_tail_sequence =
1745+
++journal->j_transaction_sequence;
1746+
write_unlock(&journal->j_state_lock);
1747+
1748+
jbd2_mark_journal_empty(journal, WRITE_FLUSH_FUA);
17421749
mutex_unlock(&journal->j_checkpoint_mutex);
17431750
} else
17441751
err = -EIO;
@@ -1997,7 +2004,7 @@ int jbd2_journal_flush(journal_t *journal)
19972004
* the magic code for a fully-recovered superblock. Any future
19982005
* commits of data to the journal will restore the current
19992006
* s_start value. */
2000-
jbd2_mark_journal_empty(journal);
2007+
jbd2_mark_journal_empty(journal, WRITE_FUA);
20012008
mutex_unlock(&journal->j_checkpoint_mutex);
20022009
write_lock(&journal->j_state_lock);
20032010
J_ASSERT(!journal->j_running_transaction);
@@ -2043,7 +2050,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)
20432050
if (write) {
20442051
/* Lock to make assertions happy... */
20452052
mutex_lock(&journal->j_checkpoint_mutex);
2046-
jbd2_mark_journal_empty(journal);
2053+
jbd2_mark_journal_empty(journal, WRITE_FUA);
20472054
mutex_unlock(&journal->j_checkpoint_mutex);
20482055
}
20492056

0 commit comments

Comments
 (0)