From: Guangshuo Li <lgs201920130244@gmail.com>
To: "Md. Haris Iqbal" <haris.iqbal@ionos.com>,
Jack Wang <jinpu.wang@ionos.com>, Jens Axboe <axboe@kernel.dk>,
Danil Kipnis <danil.kipnis@cloud.ionos.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Bart Van Assche <bvanassche@acm.org>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Subject: [PATCH] block/rnbd: Fix double free in process_msg_open
Date: Tue, 14 Jul 2026 19:50:51 +0800 [thread overview]
Message-ID: <20260714115051.1401174-1-lgs201920130244@gmail.com> (raw)
process_msg_open() allocates srv_sess_dev with
rnbd_srv_create_set_sess_dev() and then initializes its embedded kobject
through rnbd_srv_create_dev_session_sysfs().
If sysfs creation fails, the helper calls kobject_put(). The final put
invokes rnbd_srv_sess_dev_release(), which reaches
rnbd_destroy_sess_dev() and frees srv_sess_dev. process_msg_open() then
jumps to free_srv_sess_dev and calls kfree() on the same object again,
resulting in a double free.
Add the session device to the list and release srv_dev->lock before
creating the sysfs entries. On failure, rely on the kobject release
callback as the sole owner of the cleanup instead of freeing the object
again.
This issue was found by a static analysis tool I am developing.
Fixes: 8cee532f469b ("block/rnbd: server: sysfs interface functions")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/block/rnbd/rnbd-srv.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c
index 10e8c438bb43..5a991bfbf3ad 100644
--- a/drivers/block/rnbd/rnbd-srv.c
+++ b/drivers/block/rnbd/rnbd-srv.c
@@ -778,18 +778,22 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
}
}
+ /*
+ * Add the session device to the list before initializing its
+ * kobject. If sysfs creation fails, kobject_put() invokes the
+ * release callback, which removes the object from this list and
+ * releases all resources associated with the session device.
+ */
+ list_add(&srv_sess_dev->dev_list, &srv_dev->sess_dev_list);
+ mutex_unlock(&srv_dev->lock);
+
ret = rnbd_srv_create_dev_session_sysfs(srv_sess_dev);
if (ret) {
- mutex_unlock(&srv_dev->lock);
- rnbd_srv_err(srv_sess_dev,
- "Opening device failed, failed to create dev client sysfs files, err: %d\n",
- ret);
- goto free_srv_sess_dev;
+ pr_err("Opening device '%s' on session %s failed, failed to create dev client sysfs files, err: %d\n",
+ full_path, srv_sess->sessname, ret);
+ goto free_path;
}
- list_add(&srv_sess_dev->dev_list, &srv_dev->sess_dev_list);
- mutex_unlock(&srv_dev->lock);
-
rnbd_srv_info(srv_sess_dev, "Opened device '%s'\n", srv_dev->name);
kfree(full_path);
--
2.43.0
next reply other threads:[~2026-07-14 11:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 11:50 Guangshuo Li [this message]
2026-07-17 9:47 ` [PATCH] block/rnbd: Fix double free in process_msg_open Jinpu Wang
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=20260714115051.1401174-1-lgs201920130244@gmail.com \
--to=lgs201920130244@gmail.com \
--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 \
/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