mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bilal Hashim <AeeSec@126.com>
To: Damien Le Moal <dlemoal@kernel.org>,
	Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] zloop: log new device before marking it live
Date: Wed, 02 Dec 2026 02:55:21 +0800	[thread overview]
Message-ID: <179615132148.19728.4925137631421296369@126.com> (raw)

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:


                 reply	other threads:[~2026-12-01 18:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179615132148.19728.4925137631421296369@126.com \
    --to=aeesec@126.com \
    --cc=axboe@kernel.dk \
    --cc=dlemoal@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®