* [PATCH v2] zloop: log new device before marking it live
@ 2026-12-01 18:55 Bilal Hashim
2026-12-02 5:50 ` Damien Le Moal
2026-12-02 6:30 ` Christoph Hellwig
0 siblings, 2 replies; 3+ messages in thread
From: Bilal Hashim @ 2026-12-01 18:55 UTC (permalink / raw)
To: Damien Le Moal, Christoph Hellwig, Jens Axboe; +Cc: linux-block, linux-kernel
In zloop_ctl_add(), zlo->state is transitioned to Zlo_live and
zloop_ctl_mutex is unlocked before logging zlo fields with pr_info().
Once zlo->state becomes Zlo_live, a concurrent zloop_ctl_remove() can
remove the device and free zlo via put_disk() -> zloop_free_disk() before
pr_info() reads zlo->id, zlo->nr_zones, zlo->zone_size, zlo->block_size,
zlo->ordered_zone_append, and zlo->zone_append, resulting in a
slab-use-after-free read.
Move the two pr_info() calls before transitioning zlo->state to Zlo_live.
Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
Changes in v2:
- Drop the out_cleanup_disk change from v1: disk_release() only invokes
fops->free_disk() when GD_ADDED is set (at the end of add_disk_final()),
so put_disk() on blk_revalidate_disk_zones() / add_disk() failure does
not call zloop_free_disk() and the fall-through cleanup is required.
- Narrow the patch and commit message to the pr_info() use-after-free
read race only, and drop Cc: stable.
---
drivers/block/zloop.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 9666674..a26021a 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1360,10 +1360,6 @@ static int zloop_ctl_add(struct zloop_options *opts)
goto out_cleanup_disk;
}
- mutex_lock(&zloop_ctl_mutex);
- WRITE_ONCE(zlo->state, Zlo_live);
- mutex_unlock(&zloop_ctl_mutex);
-
pr_info("zloop: device %d, %u zones of %llu MiB, %u B block size\n",
zlo->id, zlo->nr_zones,
((sector_t)zlo->zone_size << SECTOR_SHIFT) >> 20,
@@ -1373,6 +1369,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
zlo->ordered_zone_append ? "ordered " : "",
zlo->zone_append ? "native" : "emulated");
+ mutex_lock(&zloop_ctl_mutex);
+ WRITE_ONCE(zlo->state, Zlo_live);
+ mutex_unlock(&zloop_ctl_mutex);
+
return 0;
out_cleanup_disk:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] zloop: log new device before marking it live
2026-12-01 18:55 [PATCH v2] zloop: log new device before marking it live Bilal Hashim
@ 2026-12-02 5:50 ` Damien Le Moal
2026-12-02 6:30 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2026-12-02 5:50 UTC (permalink / raw)
To: Bilal Hashim, Christoph Hellwig, Jens Axboe; +Cc: linux-block, linux-kernel
On 12/2/26 03:55, Bilal Hashim wrote:
> In zloop_ctl_add(), zlo->state is transitioned to Zlo_live and
> zloop_ctl_mutex is unlocked before logging zlo fields with pr_info().
>
> Once zlo->state becomes Zlo_live, a concurrent zloop_ctl_remove() can
> remove the device and free zlo via put_disk() -> zloop_free_disk() before
> pr_info() reads zlo->id, zlo->nr_zones, zlo->zone_size, zlo->block_size,
> zlo->ordered_zone_append, and zlo->zone_append, resulting in a
> slab-use-after-free read.
>
> Move the two pr_info() calls before transitioning zlo->state to Zlo_live.
>
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Signed-off-by: Bilal Hashim <AeeSec@126.com>
Looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] zloop: log new device before marking it live
2026-12-01 18:55 [PATCH v2] zloop: log new device before marking it live Bilal Hashim
2026-12-02 5:50 ` Damien Le Moal
@ 2026-12-02 6:30 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-12-02 6:30 UTC (permalink / raw)
To: Bilal Hashim; +Cc: Damien Le Moal, Jens Axboe, linux-block, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 6:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 18:55 [PATCH v2] zloop: log new device before marking it live Bilal Hashim
2026-12-02 5:50 ` Damien Le Moal
2026-12-02 6:30 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®