From: Pavel Skripkin <paskripkin@gmail.com>
To: dledford@redhat.com, jgg@ziepe.ca, leon@kernel.org, shayd@nvidia.com
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
Pavel Skripkin <paskripkin@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] infiniband: core: fix memory leak
Date: Sat, 5 Jun 2021 23:20:51 +0300 [thread overview]
Message-ID: <20210605202051.14783-1-paskripkin@gmail.com> (raw)
My local syzbot instance hit memory leak in
copy_process(). The problem was in unputted task
struct in _destroy_id().
Simple reproducer:
int main(void)
{
struct rdma_ucm_cmd_hdr *hdr;
struct rdma_ucm_create_id *cmd_id;
char cmd[sizeof(*hdr) + sizeof(*cmd_id)] = {0};
int fd;
hdr = (struct rdma_ucm_cmd_hdr *)cmd;
cmd_id = (struct rdma_ucm_create_id *) (cmd + sizeof(*hdr));
hdr->cmd = 0;
hdr->in = 0x18;
hdr->out = 0xfa00;
cmd_id->uid = 0x3;
cmd_id->response = 0x0;
cmd_id->ps = 0x106;
fd = open("/dev/infiniband/rdma_cm", O_WRONLY);
write(fd, cmd, sizeof(cmd));
}
Ftrace log:
ucma_open();
ucma_write() {
ucma_create_id() {
ucma_alloc_ctx();
rdma_create_user_id() {
rdma_restrack_new();
rdma_restrack_set_name() {
rdma_restrack_attach_task.part.0(); <--- task_struct getted
}
}
ucma_destroy_private_ctx() {
ucma_put_ctx();
rdma_destroy_id() {
_destroy_id() <--- id_priv freed
}
}
}
}
ucma_close();
From previous log it's easy to undertand that
_destroy_id() is the last place, where task_struct
can be putted, because at the end of this function
id_priv is freed.
With this patch applied, above reproducer doesn't hit memory
leak anymore.
Fixes: e51060f08a61 ("IB: IP address based RDMA connection manager")
Cc: <stable@vger.kernel.org>
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
drivers/infiniband/core/cma.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index ab148a696c0c..2760352261b3 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1874,6 +1874,7 @@ static void _destroy_id(struct rdma_id_private *id_priv,
kfree(id_priv->id.route.path_rec);
+ rdma_restrack_put(&id_priv->res);
put_net(id_priv->id.route.addr.dev_addr.net);
kfree(id_priv);
}
--
2.31.1
next reply other threads:[~2021-06-05 20:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-05 20:20 Pavel Skripkin [this message]
2021-06-06 5:21 ` [PATCH] infiniband: core: fix memory leak Leon Romanovsky
2021-06-06 8:42 ` Pavel Skripkin
2021-06-07 23:44 ` Jason Gunthorpe
2021-06-08 5:33 ` Leon Romanovsky
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=20210605202051.14783-1-paskripkin@gmail.com \
--to=paskripkin@gmail.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=shayd@nvidia.com \
--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