Skip to content

Commit

Permalink
writeback: Fix bdi use after free in wb_work_complete()
Browse files Browse the repository at this point in the history
By the time bdi_work_on_stack gets evaluated again in bdi_work_free, it
can already have been deallocated and used for something else in the
!on stack case, giving a false positive in this test and causing
corruption.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Nick Piggin authored and Jens Axboe committed Sep 16, 2009
1 parent 77fad5e commit 77b9d05
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/fs-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ static void bdi_work_free(struct rcu_head *head)
static void wb_work_complete(struct bdi_work *work)
{
const enum writeback_sync_modes sync_mode = work->args.sync_mode;
int onstack = bdi_work_on_stack(work);

/*
* For allocated work, we can clear the done/seen bit right here.
* For on-stack work, we need to postpone both the clear and free
* to after the RCU grace period, since the stack could be invalidated
* as soon as bdi_work_clear() has done the wakeup.
*/
if (!bdi_work_on_stack(work))
if (!onstack)
bdi_work_clear(work);
if (sync_mode == WB_SYNC_NONE || bdi_work_on_stack(work))
if (sync_mode == WB_SYNC_NONE || onstack)
call_rcu(&work->rcu_head, bdi_work_free);
}

Expand Down

0 comments on commit 77b9d05

Please sign in to comment.