Re: [PATCH] bcache: fix uninitialized closure object
"Coly Li" <[email protected]> Fri, 3 Apr 2026 12:04:04 +0800
| Newsgroups | org.kernel.vger.linux-bcache |
|---|---|
| Message-ID | <ac87Xq4zNhOJ64Cx@loaclhost> |
On Thu, Apr 02, 2026 at 09:03:53PM +0800, [email protected] wrote: > From: Mingzhe Zou <[email protected]> > > In the previous patch(bcache: fix cached_dev.sb_bio use-after-free and crash), > we adopted a simple modification suggestion from AI to fix the use-after-free. > > But in actual testing, we found an extreme case where the device is stopped > before calling bch_write_bdev_super(). > > At this point, struct closure sb_write has not been initialized yet. > > For this patch, we ensure that sb_bio has been completed via sb_write_mutex. > > Signed-off-by: Mingzhe Zou <[email protected]> It looks good to me. I will refine the commit log and submit. Thanks. Coly Li > --- > drivers/md/bcache/super.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > index 6627a381f65a..97d9adb0bf96 100644 > --- a/drivers/md/bcache/super.c > +++ b/drivers/md/bcache/super.c > @@ -1378,7 +1378,8 @@ static CLOSURE_CALLBACK(cached_dev_free) > * The sb_bio is embedded in struct cached_dev, so we must > * ensure no I/O is in progress. > */ > - closure_sync(&dc->sb_write); > + down(&dc->sb_write_mutex); > + up(&dc->sb_write_mutex); > > if (dc->sb_disk) > folio_put(virt_to_folio(dc->sb_disk)); > -- > 2.34.1