From: Miaoqian Lin <linmq006@gmail.com>
To: "Md. Haris Iqbal" <haris.iqbal@ionos.com>,
Jack Wang <jinpu.wang@ionos.com>, Jason Gunthorpe <jgg@ziepe.ca>,
Danil Kipnis <danil.kipnis@cloud.ionos.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: linmq006@gmail.com
Subject: [PATCH v2] RDMA/rtrs: Fix double free in alloc_clt
Date: Mon, 24 Jan 2022 12:21:35 +0000 [thread overview]
Message-ID: <20220124122135.5745-1-linmq006@gmail.com> (raw)
Callback function rtrs_clt_dev_release() in put_device()
calls kfree(clt); to free memory. We shouldn't call kfree(clt) again.
Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
Changes in v2:
- call free_percpu() before put_device() to avoid UAF.
---
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 7c3f98e57889..aff04f566304 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -2739,10 +2739,8 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num,
*/
dev_set_uevent_suppress(&clt->dev, true);
err = device_register(&clt->dev);
- if (err) {
- put_device(&clt->dev);
- goto err;
- }
+ if (err)
+ goto err_register;
clt->kobj_paths = kobject_create_and_add("paths", &clt->dev.kobj);
if (!clt->kobj_paths) {
@@ -2764,6 +2762,11 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num,
err:
free_percpu(clt->pcpu_path);
kfree(clt);
+ goto ret;
+err_register:
+ free_percpu(clt->pcpu_path);
+ put_device(&clt->dev);
+ret:
return ERR_PTR(err);
}
--
2.17.1
next reply other threads:[~2022-01-24 12:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 12:21 Miaoqian Lin [this message]
2022-01-24 21:55 ` 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=20220124122135.5745-1-linmq006@gmail.com \
--to=linmq006@gmail.com \
--cc=danil.kipnis@cloud.ionos.com \
--cc=haris.iqbal@ionos.com \
--cc=jgg@ziepe.ca \
--cc=jinpu.wang@ionos.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@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
Powered by JetHome