Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: clear ia_ranges on sysfs registration failure
@ 2026-08-14 22:04 Shuangpeng Bai
  2026-08-17  7:46 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Shuangpeng Bai @ 2026-08-14 22:04 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, Shuangpeng Bai, stable

disk_register_independent_access_ranges() clears disk->ia_ranges when
creating the top-level kobject fails. However, if adding one of the range
kobjects fails, the cleanup drops the final reference to iars and frees it
while disk->ia_ranges still points at it.

A concurrent disk revalidation can wait for q->sysfs_lock and then call
disk_unregister_independent_access_ranges(), which dereferences the stale
pointer after registration releases the mutex.

Clear disk->ia_ranges before dropping the kobject references on the child
registration error path, matching the top-level error handling.

Fixes: a2247f19ee1c ("block: Add independent access ranges support")
Cc: stable@vger.kernel.org
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
---
 block/blk-ia-ranges.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/blk-ia-ranges.c b/block/blk-ia-ranges.c
index 7be8b58893c9..2430e475a8e7 100644
--- a/block/blk-ia-ranges.c
+++ b/block/blk-ia-ranges.c
@@ -135,6 +135,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk)
 					   &blk_ia_range_ktype, &iars->kobj,
 					   "%d", i);
 		if (ret) {
+			disk->ia_ranges = NULL;
 			while (--i >= 0)
 				kobject_del(&iars->ia_range[i].kobj);
 			kobject_del(&iars->kobj);
-- 
2.43.0


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

* Re: [PATCH] block: clear ia_ranges on sysfs registration failure
  2026-08-14 22:04 [PATCH] block: clear ia_ranges on sysfs registration failure Shuangpeng Bai
@ 2026-08-17  7:46 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-08-17  7:46 UTC (permalink / raw)
  To: Shuangpeng Bai; +Cc: axboe, linux-block, linux-kernel, stable

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

On Fri, Aug 14, 2026 at 06:04:48PM -0400, Shuangpeng Bai wrote:
> disk_register_independent_access_ranges() clears disk->ia_ranges when
> creating the top-level kobject fails. However, if adding one of the range
> kobjects fails, the cleanup drops the final reference to iars and frees it
> while disk->ia_ranges still points at it.
> 
> A concurrent disk revalidation can wait for q->sysfs_lock and then call
> disk_unregister_independent_access_ranges(), which dereferences the stale
> pointer after registration releases the mutex.
> 
> Clear disk->ia_ranges before dropping the kobject references on the child
> registration error path, matching the top-level error handling.
> 
> Fixes: a2247f19ee1c ("block: Add independent access ranges support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
> ---
>  block/blk-ia-ranges.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/blk-ia-ranges.c b/block/blk-ia-ranges.c
> index 7be8b58893c9..2430e475a8e7 100644
> --- a/block/blk-ia-ranges.c
> +++ b/block/blk-ia-ranges.c
> @@ -135,6 +135,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk)
>  					   &blk_ia_range_ktype, &iars->kobj,
>  					   "%d", i);
>  		if (ret) {
> +			disk->ia_ranges = NULL;
>  			while (--i >= 0)
>  				kobject_del(&iars->ia_range[i].kobj);
>  			kobject_del(&iars->kobj);
> -- 
> 2.43.0
> 
> 
---end quoted text---

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

end of thread, other threads:[~2026-08-17  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 22:04 [PATCH] block: clear ia_ranges on sysfs registration failure Shuangpeng Bai
2026-08-17  7:46 ` Christoph Hellwig

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