[PATCH v2] zloop: log new device before marking it live

From: Bilal Hashim

Date: Tue Dec 01 2026 - 13:56:45 EST


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@xxxxxxx>
---
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: