public inbox for linux-bcache@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bcache: fix uninitialized closure object
@ 2026-04-02 13:03 mingzhe.zou
  2026-04-03  4:04 ` Coly Li
  0 siblings, 1 reply; 10+ messages in thread
From: mingzhe.zou @ 2026-04-02 13:03 UTC (permalink / raw)
  To: colyli, colyli; +Cc: linux-bcache, zoumingzhe, zoumingzhe, Mingzhe Zou

From: Mingzhe Zou <zoumingzhe@qq.com>

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>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-02 13:03 [PATCH] bcache: fix uninitialized closure object mingzhe.zou
@ 2026-04-03  4:04 ` Coly Li
  0 siblings, 0 replies; 10+ messages in thread
From: Coly Li @ 2026-04-03  4:04 UTC (permalink / raw)
  To: mingzhe.zou; +Cc: colyli, linux-bcache, zoumingzhe, zoumingzhe

On Thu, Apr 02, 2026 at 09:03:53PM +0800, mingzhe.zou@easystack.cn wrote:
> From: Mingzhe Zou <zoumingzhe@qq.com>
> 
> 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>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] bcache: fix uninitialized closure object
@ 2026-04-03  4:21 colyli
  2026-04-03 11:11 ` Jens Axboe
  2026-04-03 11:11 ` Jens Axboe
  0 siblings, 2 replies; 10+ messages in thread
From: colyli @ 2026-04-03  4:21 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-bcache, Mingzhe Zou, Coly Li

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.

(Coly Li refines the commit log.)

Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@fnnas.com>
---
 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 5005a26af363..5380a44ef721 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.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-03  4:21 colyli
@ 2026-04-03 11:11 ` Jens Axboe
  2026-04-07  9:28   ` Coly Li
  2026-04-03 11:11 ` Jens Axboe
  1 sibling, 1 reply; 10+ messages in thread
From: Jens Axboe @ 2026-04-03 11:11 UTC (permalink / raw)
  To: colyli; +Cc: linux-block, linux-bcache, Mingzhe Zou

On 4/2/26 10:21 PM, 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.

Presumably this should have a:

Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")

but for some reason it does not. I'll add it.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-03  4:21 colyli
  2026-04-03 11:11 ` Jens Axboe
@ 2026-04-03 11:11 ` Jens Axboe
  1 sibling, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2026-04-03 11:11 UTC (permalink / raw)
  To: colyli; +Cc: linux-block, linux-bcache, Mingzhe Zou


On Fri, 03 Apr 2026 12:21:35 +0800, colyli@fnnas.com wrote:
> 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().
> 
> [...]

Applied, thanks!

[1/1] bcache: fix uninitialized closure object
      commit: 20a8e451ec1c7e99060b1bbaaad03ce88c39ddb8

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-03 11:11 ` Jens Axboe
@ 2026-04-07  9:28   ` Coly Li
  2026-04-07 12:44     ` Jens Axboe
  0 siblings, 1 reply; 10+ messages in thread
From: Coly Li @ 2026-04-07  9:28 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-bcache, Mingzhe Zou

> 2026年4月3日 19:11,Jens Axboe <axboe@kernel.dk> 写道:
> 
> On 4/2/26 10:21 PM, 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.
> 
> Presumably this should have a:
> 
> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
> 
> but for some reason it does not. I'll add it.

I did it on purpose. Because this patch is in Linux-stable and not in mainline,
I am not sure whether it is proper to reference the linux-block tree commit id.

This is why the patch title is mentioned in commit log, but commit id skipped.

Thanks for adding it.

Coly Li

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-07  9:28   ` Coly Li
@ 2026-04-07 12:44     ` Jens Axboe
  2026-04-07 13:19       ` Coly Li
  0 siblings, 1 reply; 10+ messages in thread
From: Jens Axboe @ 2026-04-07 12:44 UTC (permalink / raw)
  To: Coly Li; +Cc: linux-block, linux-bcache, Mingzhe Zou

On 4/7/26 3:28 AM, Coly Li wrote:
>> 2026?4?3? 19:11?Jens Axboe <axboe@kernel.dk> ???
>>
>> On 4/2/26 10:21 PM, 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.
>>
>> Presumably this should have a:
>>
>> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
>>
>> but for some reason it does not. I'll add it.
> 
> I did it on purpose. Because this patch is in Linux-stable and not in mainline,
> I am not sure whether it is proper to reference the linux-block tree commit id.
> 
> This is why the patch title is mentioned in commit log, but commit id skipped.

Why is the patch in stable and not in mainline?! That should generally
never happen.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-07 12:44     ` Jens Axboe
@ 2026-04-07 13:19       ` Coly Li
  2026-04-07 13:24         ` Jens Axboe
  0 siblings, 1 reply; 10+ messages in thread
From: Coly Li @ 2026-04-07 13:19 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-bcache, Mingzhe Zou

> 2026年4月7日 20:44,Jens Axboe <axboe@kernel.dk> 写道:
> 
> On 4/7/26 3:28 AM, Coly Li wrote:
>>> 2026?4?3? 19:11?Jens Axboe <axboe@kernel.dk> ???
>>> 
>>> On 4/2/26 10:21 PM, 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.
>>> 
>>> Presumably this should have a:
>>> 
>>> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
>>> 
>>> but for some reason it does not. I'll add it.
>> 
>> I did it on purpose. Because this patch is in Linux-stable and not in mainline,
>> I am not sure whether it is proper to reference the linux-block tree commit id.
>> 
>> This is why the patch title is mentioned in commit log, but commit id skipped.
> 
> Why is the patch in stable and not in mainline?! That should generally
> never happen.

Oops, My fingers movement diverged from my brain. I thought linux-block, but typed linux-stable….

I meant, when the patch merged from linux-block to Linus tree, maybe the commit id changes
for some unexpected reason. So I didn’t reference the Fixes tag with linux-block tree commit
id.

Coly Li

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-07 13:19       ` Coly Li
@ 2026-04-07 13:24         ` Jens Axboe
  2026-04-07 14:09           ` Coly Li
  0 siblings, 1 reply; 10+ messages in thread
From: Jens Axboe @ 2026-04-07 13:24 UTC (permalink / raw)
  To: Coly Li; +Cc: linux-block, linux-bcache, Mingzhe Zou

On 4/7/26 7:19 AM, Coly Li wrote:
>> 2026?4?7? 20:44?Jens Axboe <axboe@kernel.dk> ???
>>
>> On 4/7/26 3:28 AM, Coly Li wrote:
>>>> 2026?4?3? 19:11?Jens Axboe <axboe@kernel.dk> ???
>>>>
>>>> On 4/2/26 10:21 PM, 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.
>>>>
>>>> Presumably this should have a:
>>>>
>>>> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
>>>>
>>>> but for some reason it does not. I'll add it.
>>>
>>> I did it on purpose. Because this patch is in Linux-stable and not in mainline,
>>> I am not sure whether it is proper to reference the linux-block tree commit id.
>>>
>>> This is why the patch title is mentioned in commit log, but commit id skipped.
>>
>> Why is the patch in stable and not in mainline?! That should generally
>> never happen.
> 
> Oops, My fingers movement diverged from my brain. I thought
> linux-block, but typed linux-stable?.
> 
> I meant, when the patch merged from linux-block to Linus tree, maybe
> the commit id changes for some unexpected reason. So I didn?t
> reference the Fixes tag with linux-block tree commit id.

It'll never change going into Linus's tree, that's how git works. If I
have a rare rebase for whatever reason, I fixup the Fixes shas. So
always put them in there, there's never a reason NOT to do so.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] bcache: fix uninitialized closure object
  2026-04-07 13:24         ` Jens Axboe
@ 2026-04-07 14:09           ` Coly Li
  0 siblings, 0 replies; 10+ messages in thread
From: Coly Li @ 2026-04-07 14:09 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-bcache, Mingzhe Zou

> 2026年4月7日 21:24,Jens Axboe <axboe@kernel.dk> 写道:
> 
> On 4/7/26 7:19 AM, Coly Li wrote:
>>> 2026?4?7? 20:44?Jens Axboe <axboe@kernel.dk> ???
>>> 
>>> On 4/7/26 3:28 AM, Coly Li wrote:
>>>>> 2026?4?3? 19:11?Jens Axboe <axboe@kernel.dk> ???
>>>>> 
>>>>> On 4/2/26 10:21 PM, 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.
>>>>> 
>>>>> Presumably this should have a:
>>>>> 
>>>>> Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
>>>>> 
>>>>> but for some reason it does not. I'll add it.
>>>> 
>>>> I did it on purpose. Because this patch is in Linux-stable and not in mainline,
>>>> I am not sure whether it is proper to reference the linux-block tree commit id.
>>>> 
>>>> This is why the patch title is mentioned in commit log, but commit id skipped.
>>> 
>>> Why is the patch in stable and not in mainline?! That should generally
>>> never happen.
>> 
>> Oops, My fingers movement diverged from my brain. I thought
>> linux-block, but typed linux-stable?.
>> 
>> I meant, when the patch merged from linux-block to Linus tree, maybe
>> the commit id changes for some unexpected reason. So I didn?t
>> reference the Fixes tag with linux-block tree commit id.
> 
> It'll never change going into Linus's tree, that's how git works. If I
> have a rare rebase for whatever reason, I fixup the Fixes shas. So
> always put them in there, there's never a reason NOT to do so.

This is a clear hint. Thanks.

Coly Li

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-04-07 14:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 13:03 [PATCH] bcache: fix uninitialized closure object mingzhe.zou
2026-04-03  4:04 ` Coly Li
  -- strict thread matches above, loose matches on Subject: below --
2026-04-03  4:21 colyli
2026-04-03 11:11 ` Jens Axboe
2026-04-07  9:28   ` Coly Li
2026-04-07 12:44     ` Jens Axboe
2026-04-07 13:19       ` Coly Li
2026-04-07 13:24         ` Jens Axboe
2026-04-07 14:09           ` Coly Li
2026-04-03 11:11 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox