Skip to content

Commit

Permalink
reiserfs: Fix use after free in journal teardown
Browse files Browse the repository at this point in the history
If do_journal_release() races with do_journal_end() which requeues
delayed works for transaction flushing, we can leave work items for
flushing outstanding transactions queued while freeing them. That
results in use after free and possible crash in run_timers_softirq().

Fix the problem by not requeueing works if superblock is being shut down
(MS_ACTIVE not set) and using cancel_delayed_work_sync() in
do_journal_release().

CC: [email protected]
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
jankara committed Aug 12, 2014
1 parent 27d0e5b commit 0177783
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 16 additions & 6 deletions fs/reiserfs/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,17 +1947,21 @@ static int do_journal_release(struct reiserfs_transaction_handle *th,
}
}

/* wait for all commits to finish */
cancel_delayed_work(&SB_JOURNAL(sb)->j_work);

/*
* We must release the write lock here because
* the workqueue job (flush_async_commit) needs this lock
*/
reiserfs_write_unlock(sb);

/*
* Cancel flushing of old commits. Note that neither of these works
* will be requeued because superblock is being shutdown and doesn't
* have MS_ACTIVE set.
*/
cancel_delayed_work_sync(&REISERFS_SB(sb)->old_work);
flush_workqueue(REISERFS_SB(sb)->commit_wq);
/* wait for all commits to finish */
cancel_delayed_work_sync(&SB_JOURNAL(sb)->j_work);

free_journal_ram(sb);

Expand Down Expand Up @@ -4292,9 +4296,15 @@ static int do_journal_end(struct reiserfs_transaction_handle *th, int flags)
if (flush) {
flush_commit_list(sb, jl, 1);
flush_journal_list(sb, jl, 1);
} else if (!(jl->j_state & LIST_COMMIT_PENDING))
queue_delayed_work(REISERFS_SB(sb)->commit_wq,
&journal->j_work, HZ / 10);
} else if (!(jl->j_state & LIST_COMMIT_PENDING)) {
/*
* Avoid queueing work when sb is being shut down. Transaction
* will be flushed on journal shutdown.
*/
if (sb->s_flags & MS_ACTIVE)
queue_delayed_work(REISERFS_SB(sb)->commit_wq,
&journal->j_work, HZ / 10);
}

/*
* if the next transaction has any chance of wrapping, flush
Expand Down
6 changes: 5 additions & 1 deletion fs/reiserfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ void reiserfs_schedule_old_flush(struct super_block *s)
struct reiserfs_sb_info *sbi = REISERFS_SB(s);
unsigned long delay;

if (s->s_flags & MS_RDONLY)
/*
* Avoid scheduling flush when sb is being shut down. It can race
* with journal shutdown and free still queued delayed work.
*/
if (s->s_flags & MS_RDONLY || !(s->s_flags & MS_ACTIVE))
return;

spin_lock(&sbi->old_work_lock);
Expand Down

0 comments on commit 0177783

Please sign in to comment.