From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 9 May 2018 12:31:35 +0200 From: Jan Kara To: linux-fsdevel@vger.kernel.org Cc: linux-block@vger.kernel.org, Jens Axboe , Jan Kara , Tetsuo Handa , Tejun Heo Subject: Re: [PATCH] bdi: Fix oops in wb_workfn() Message-ID: <20180509103135.akgp2u5pzkahji6n@quack2.suse.cz> References: <20180503162626.27753-1-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <20180503162626.27753-1-jack@suse.cz> List-ID: On Thu 03-05-18 18:26:26, Jan Kara wrote: > 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 > CC: Tejun Heo > Fixes: 839a8e8660b6777e7fe4e80af1a048aebe2b5977 > Reported-by: syzbot > Signed-off-by: Jan Kara > --- > fs/fs-writeback.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Jens, can you please pick up this patch? Probably for the next merge window (I don't see a reason to rush this at this point in release cycle). Thanks! Honza > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index 47d7c151fcba..471d863958bc 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -1961,7 +1961,7 @@ void wb_workfn(struct work_struct *work) > } > > if (!list_empty(&wb->work_list)) > - mod_delayed_work(bdi_wq, &wb->dwork, 0); > + wb_wakeup(wb); > else if (wb_has_dirty_io(wb) && dirty_writeback_interval) > wb_wakeup_delayed(wb); > > -- > 2.13.6 > -- Jan Kara SUSE Labs, CR