Skip to content

Commit 57d6410

Browse files
jankaragregkh
authored andcommitted
bdi: Fix oops in wb_workfn()
commit b8b7849 upstream. Syzbot has reported that it can hit a NULL pointer dereference in wb_workfn() due to wb->bdi->dev being NULL. This indicates that wb_workfn() was called for an already unregistered bdi which should not happen as wb_shutdown() called from bdi_unregister() should make sure all pending writeback works are completed before bdi is unregistered. Except that wb_workfn() itself can requeue the work with: mod_delayed_work(bdi_wq, &wb->dwork, 0); and if this happens while wb_shutdown() is waiting in: flush_delayed_work(&wb->dwork); the dwork can get executed after wb_shutdown() has finished and bdi_unregister() has cleared wb->bdi->dev. Make wb_workfn() use wakeup_wb() for requeueing the work which takes all the necessary precautions against racing with bdi unregistration. CC: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> CC: Tejun Heo <tj@kernel.org> Fixes: 839a8e8 Reported-by: syzbot <syzbot+9873874c735f2892e7e9@syzkaller.appspotmail.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 869f538 commit 57d6410

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/fs-writeback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ void wb_workfn(struct work_struct *work)
19421942
}
19431943

19441944
if (!list_empty(&wb->work_list))
1945-
mod_delayed_work(bdi_wq, &wb->dwork, 0);
1945+
wb_wakeup(wb);
19461946
else if (wb_has_dirty_io(wb) && dirty_writeback_interval)
19471947
wb_wakeup_delayed(wb);
19481948

0 commit comments

Comments
 (0)