* [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close()
@ 2026-09-16 9:48 Wentao Liang
2026-09-16 12:21 ` Haris Iqbal
0 siblings, 1 reply; 3+ messages in thread
From: Wentao Liang @ 2026-09-16 9:48 UTC (permalink / raw)
To: axboe
Cc: bvanassche, danil.kipnis, haris.iqbal, jgg, jinpu.wang,
linux-block, linux-kernel, Wentao Liang, stable
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close()
2026-09-16 9:48 [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close() Wentao Liang
@ 2026-09-16 12:21 ` Haris Iqbal
2026-11-07 18:40 ` Wentao Liang
0 siblings, 1 reply; 3+ messages in thread
From: Haris Iqbal @ 2026-09-16 12:21 UTC (permalink / raw)
To: Wentao Liang
Cc: axboe, bvanassche, danil.kipnis, jgg, jinpu.wang, linux-block,
linux-kernel, stable
On Wed, Sep 16, 2026 at 11:48 AM Wentao Liang <vulab@iscas.ac.cn> wrote:
>
> 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);
Thanks for the patch.
Sashiko has critical finding about this change.
https://sashiko.dev/#/patchset/20260916094817.2007756-1-vulab%40iscas.ac.cn
Can you please review that?
> }
>
> static int process_msg_open(struct rnbd_srv_session *srv_sess,
> --
> 2.34.1
>
--
Regards
-Haris
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close()
2026-09-16 12:21 ` Haris Iqbal
@ 2026-11-07 18:40 ` Wentao Liang
0 siblings, 0 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-07 18:40 UTC (permalink / raw)
To: Haris Iqbal
Cc: axboe, bvanassche, danil.kipnis, jgg, jinpu.wang, linux-block,
linux-kernel, vulab
Hi Haris,
Sorry for the very late reply. Your message arrived when I was already
behind on this thread, and then it sat far longer than it should have.
That is my fault, not a sign that the report was unimportant.
I have now gone through the Sashiko report, and it is right: the patch is
wrong in exactly the way it describes.
process_msg_close() takes a kref with rnbd_get_sess_dev() and then calls
rnbd_srv_destroy_dev_session_sysfs(). That kobject_put() drops the last
kobject reference, so rnbd_srv_sess_dev_release() -> rnbd_destroy_sess_dev()
runs synchronously in the same thread, still under srv_sess->lock. That
function does rnbd_put_sess_dev() and then waits on destroy_comp, but the
reference this thread holds is only dropped after the wait returns. So a
single CLOSE from a client hangs the teardown thread with the session lock
held - I traded the race for a guaranteed deadlock, which is worse than
what I set out to fix.
While checking this against the current tree I also found that the race
itself has meanwhile been fixed upstream:
4912dab88baa ("rnbd-srv: fix use-after-free on two CLOSE messages")
It takes srv_sess->lock first and looks the ID up with xa_load() under it,
so a second teardown of the same ID finds nothing. It is in v7.4-rc1, and
it also covers the force_close() interleaving that my patch was trying to
address. A v2 of my patch would therefore only duplicate work that is
already merged, so please drop this one - there is nothing here for you to
apply.
Thanks for pointing me at the Sashiko report.
Regards,
Wentao
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-07 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 9:48 [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close() Wentao Liang
2026-09-16 12:21 ` Haris Iqbal
2026-11-07 18:40 ` Wentao Liang
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®