Linux block layer
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: axboe@kernel.dk
Cc: bvanassche@acm.org, danil.kipnis@cloud.ionos.com,
	haris.iqbal@ionos.com, jgg@ziepe.ca, jinpu.wang@ionos.com,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close()
Date: Wed, 16 Sep 2026 09:48:17 +0000	[thread overview]
Message-ID: <20260916094817.2007756-1-vulab@iscas.ac.cn> (raw)

process_msg_close() drops the device reference with rnbd_put_sess_dev()
before using sess_dev again in rnbd_srv_destroy_dev_session_sysfs().
If that put drops the last kref, e.g. when the device is concurrently
being torn down through rnbd_srv_sess_dev_force_close(), the waiter in
rnbd_destroy_sess_dev() is woken up and frees sess_dev, so the
subsequent rnbd_srv_destroy_dev_session_sysfs() call operates on freed
memory.

Move the rnbd_put_sess_dev() call after the sysfs teardown so it is the
last access to sess_dev.

Fixes: 2de6c8de192b ("block/rnbd: server: main functionality")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/block/rnbd/rnbd-srv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c
index 10e8c438bb43..2ebc2eac384f 100644
--- a/drivers/block/rnbd/rnbd-srv.c
+++ b/drivers/block/rnbd/rnbd-srv.c
@@ -361,10 +361,10 @@ static void process_msg_close(struct rnbd_srv_session *srv_sess,
 	if (IS_ERR(sess_dev))
 		return;
 
-	rnbd_put_sess_dev(sess_dev);
 	mutex_lock(&srv_sess->lock);
 	rnbd_srv_destroy_dev_session_sysfs(sess_dev);
 	mutex_unlock(&srv_sess->lock);
+	rnbd_put_sess_dev(sess_dev);
 }
 
 static int process_msg_open(struct rnbd_srv_session *srv_sess,
-- 
2.34.1


             reply	other threads:[~2026-09-16  9:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  9:48 Wentao Liang [this message]
2026-09-16 12:21 ` [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close() Haris Iqbal
2026-11-07 18:40   ` Wentao Liang

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=20260916094817.2007756-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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