Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: avoid use-after-free in disk_free_zone_resources()
@ 2026-05-22 11:56 Damien Le Moal
  2026-05-22 12:09 ` Christoph Hellwig
  2026-05-22 14:06 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Damien Le Moal @ 2026-05-22 11:56 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Christoph Hellwig

The function disk_update_zone_resources() may call
disk_free_zone_resources() in case of error, and following this,
blk_revalidate_disk_zones() will again calls disk_free_zone_resources() if
disk_update_zone_resources() failed. If a zone worker thread is being used
(which is the default for a rotational media zoned device),
disk_free_zone_resources() will try to stop the zone worker thread twice
because disk->zone_wplugs_worker is not reset to NULL when the worker
thread is stopped the first time.

In disk_free_zone_resources(), fix this by correctly clearing
disk->zone_wplugs_worker to NULL when the worker thread is stopped.

And while at it, since disk_free_zone_resources() is always called after a
failed call to disk_update_zone_resources(), remove the unnecessary call
to disk_free_zone_resources() in disk_update_zone_resources().

Fixes: 1365b6904fd0 ("block: allow submitting all zone writes from a single context")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-zoned.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 42ef830054dc..6a221c180889 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -2001,8 +2001,10 @@ static void disk_set_zones_cond_array(struct gendisk *disk, u8 *zones_cond)
 
 void disk_free_zone_resources(struct gendisk *disk)
 {
-	if (disk->zone_wplugs_worker)
+	if (disk->zone_wplugs_worker) {
 		kthread_stop(disk->zone_wplugs_worker);
+		disk->zone_wplugs_worker = NULL;
+	}
 	WARN_ON_ONCE(!list_empty(&disk->zone_wplugs_list));
 
 	if (disk->zone_wplugs_wq) {
@@ -2135,9 +2137,6 @@ static int disk_update_zone_resources(struct gendisk *disk,
 	ret = queue_limits_commit_update(q, &lim);
 
 unfreeze:
-	if (ret)
-		disk_free_zone_resources(disk);
-
 	blk_mq_unfreeze_queue(q, memflags);
 
 	return ret;
-- 
2.54.0


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

* Re: [PATCH] block: avoid use-after-free in disk_free_zone_resources()
  2026-05-22 11:56 [PATCH] block: avoid use-after-free in disk_free_zone_resources() Damien Le Moal
@ 2026-05-22 12:09 ` Christoph Hellwig
  2026-05-22 14:06 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-05-22 12:09 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block, Christoph Hellwig

Looks good:

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

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

* Re: [PATCH] block: avoid use-after-free in disk_free_zone_resources()
  2026-05-22 11:56 [PATCH] block: avoid use-after-free in disk_free_zone_resources() Damien Le Moal
  2026-05-22 12:09 ` Christoph Hellwig
@ 2026-05-22 14:06 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-05-22 14:06 UTC (permalink / raw)
  To: linux-block, Damien Le Moal; +Cc: Christoph Hellwig


On Fri, 22 May 2026 20:56:22 +0900, Damien Le Moal wrote:
> The function disk_update_zone_resources() may call
> disk_free_zone_resources() in case of error, and following this,
> blk_revalidate_disk_zones() will again calls disk_free_zone_resources() if
> disk_update_zone_resources() failed. If a zone worker thread is being used
> (which is the default for a rotational media zoned device),
> disk_free_zone_resources() will try to stop the zone worker thread twice
> because disk->zone_wplugs_worker is not reset to NULL when the worker
> thread is stopped the first time.
> 
> [...]

Applied, thanks!

[1/1] block: avoid use-after-free in disk_free_zone_resources()
      commit: f6982769910ecddabdb5b8b9afdab0bb8b6668ac

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-05-22 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22 11:56 [PATCH] block: avoid use-after-free in disk_free_zone_resources() Damien Le Moal
2026-05-22 12:09 ` Christoph Hellwig
2026-05-22 14:06 ` Jens Axboe

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