* [PATCH] bcache: fix uninitialized closure object
@ 2026-04-22 15:21 colyli
2026-04-23 4:55 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: colyli @ 2026-04-22 15:21 UTC (permalink / raw)
To: stable; +Cc: Mingzhe Zou, Coly Li, stable, Jens Axboe
From: Mingzhe Zou <mingzhe.zou@easystack.cn>
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 <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@fnnas.com>
Link: https://patch.msgid.link/20260403042135.2221247-1-colyli@fnnas.com
Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
Cc: stable@vger.kerenl.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
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
@@ -1376,11 +1376,12 @@ static CLOSURE_CALLBACK(cached_dev_free)
/*
* Wait for any pending sb_write to complete before 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));
if (dc->bdev_file)
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] bcache: fix uninitialized closure object
2026-04-22 15:21 [PATCH] bcache: fix uninitialized closure object colyli
@ 2026-04-23 4:55 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-04-23 4:55 UTC (permalink / raw)
To: colyli; +Cc: stable, Mingzhe Zou, stable, Jens Axboe
On Wed, Apr 22, 2026 at 11:21:13PM +0800, colyli@fnnas.com wrote:
> From: Mingzhe Zou <mingzhe.zou@easystack.cn>
>
> 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 <mingzhe.zou@easystack.cn>
> Signed-off-by: Coly Li <colyli@fnnas.com>
> Link: https://patch.msgid.link/20260403042135.2221247-1-colyli@fnnas.com
> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
> Cc: stable@vger.kerenl.org
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
> 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
> @@ -1376,11 +1376,12 @@ static CLOSURE_CALLBACK(cached_dev_free)
> /*
> * Wait for any pending sb_write to complete before 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));
>
> if (dc->bdev_file)
> --
> 2.47.3
>
>
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] bcache: fix uninitialized closure object
@ 2026-04-22 15:42 colyli
0 siblings, 0 replies; 3+ messages in thread
From: colyli @ 2026-04-22 15:42 UTC (permalink / raw)
To: stable
From: Mingzhe Zou <mingzhe.zou@easystack.cn>
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 <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@fnnas.com>
Link: https://patch.msgid.link/20260403042135.2221247-1-colyli@fnnas.com
Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
Cc: stable@vger.kerenl.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
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
@@ -1376,11 +1376,12 @@ static CLOSURE_CALLBACK(cached_dev_free)
/*
* Wait for any pending sb_write to complete before 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));
if (dc->bdev_file)
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-23 4:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 15:21 [PATCH] bcache: fix uninitialized closure object colyli
2026-04-23 4:55 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2026-04-22 15:42 colyli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox