All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jack Wang <jinpu.wang@ionos.com>
To: linux-rdma@vger.kernel.org
Cc: bvanassche@acm.org, leon@kernel.org, dledford@redhat.com,
	jgg@ziepe.ca, haris.iqbal@ionos.com, jinpu.wang@ionos.com,
	Gioh Kim <gi-oh.kim@cloud.ionos.com>,
	Gioh Kim <gi-oh.kim@ionos.com>
Subject: [PATCHv3 for-next 20/20] RDMA/rtrs-clt: Fix memory leak of not-freed sess->stats and stats->pcpu_stats
Date: Fri, 28 May 2021 13:30:18 +0200	[thread overview]
Message-ID: <20210528113018.52290-21-jinpu.wang@ionos.com> (raw)
In-Reply-To: <20210528113018.52290-1-jinpu.wang@ionos.com>

From: Gioh Kim <gi-oh.kim@cloud.ionos.com>

sess->stats and sess->stats->pcpu_stats objects are freed
when sysfs entry is removed. If something wrong happens and
session is closed before sysfs entry is created,
sess->stats and sess->stats->pcpu_stats objects are not freed.

This patch adds freeing of them at three places:
1. When client uses wrong address and session creation fails.
2. When client fails to create a sysfs entry.
3. When client adds wrong address via sysfs add_path.

Fixes: 215378b838df0 ("RDMA/rtrs: client: sysfs interface functions")
Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index e4a23c40d4c7..8e05a71d8da1 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -2765,6 +2765,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
 		if (err) {
 			list_del_rcu(&sess->s.entry);
 			rtrs_clt_close_conns(sess, true);
+			free_percpu(sess->stats->pcpu_stats);
+			kfree(sess->stats);
 			free_sess(sess);
 			goto close_all_sess;
 		}
@@ -2773,6 +2775,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
 		if (err) {
 			list_del_rcu(&sess->s.entry);
 			rtrs_clt_close_conns(sess, true);
+			free_percpu(sess->stats->pcpu_stats);
+			kfree(sess->stats);
 			free_sess(sess);
 			goto close_all_sess;
 		}
@@ -3048,6 +3052,8 @@ int rtrs_clt_create_path_from_sysfs(struct rtrs_clt *clt,
 close_sess:
 	rtrs_clt_remove_path_from_arr(sess);
 	rtrs_clt_close_conns(sess, true);
+	free_percpu(sess->stats->pcpu_stats);
+	kfree(sess->stats);
 	free_sess(sess);
 
 	return err;
-- 
2.25.1


  parent reply	other threads:[~2021-05-28 11:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 11:29 [PATCHv3 for-next 00/20] RTRS update for 5.14 Jack Wang
2021-05-28 11:29 ` [PATCHv3 for-next 01/20] RDMA/rtrs-srv: Kill reject_w_econnreset label Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 02/20] RDMA/rtrs-clt: Remove MAX_SESS_QUEUE_DEPTH from rtrs_send_sess_info Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 03/20] RDMA/rtrs-srv: Add error messages for cases when failing RDMA connection Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 04/20] RDMA/rtrs-srv: Clean up the code in __rtrs_srv_change_state Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 05/20] RDMA/rtrs: Change MAX_SESS_QUEUE_DEPTH Jack Wang
2021-05-28 16:19   ` kernel test robot
2021-05-28 16:19     ` kernel test robot
2021-05-31 11:44     ` Jinpu Wang
2021-05-31 11:44       ` Jinpu Wang
2021-05-31 12:17       ` Jason Gunthorpe
2021-05-31 12:17         ` Jason Gunthorpe
2021-05-31 12:29         ` Jinpu Wang
2021-05-31 12:29           ` Jinpu Wang
2021-05-28 11:30 ` [PATCHv3 for-next 06/20] RDMA/rtrs: Define MIN_CHUNK_SIZE Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 07/20] RDMA/rtrs: Use strscpy instead of strlcpy Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 08/20] RDMA/rtrs-clt: Kill rtrs_clt_{start,stop}_hb Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 09/20] RDMA/rtrs-clt: Kill rtrs_clt_disconnect_from_sysfs Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 10/20] RDMA/rtrs-srv: Kill __rtrs_srv_change_state Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 11/20] RDMA/rtrs-clt: Remove redundant 'break' Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 12/20] RDMA/rtrs-clt: Check state of the rtrs_clt_sess before reading its stats Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 13/20] RDMA/rtrs-srv: Replace atomic_t with percpu_ref for ids_inflight Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 14/20] RDMA/rtrs-srv: convert scnprintf to sysfs_emit Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 15/20] RDMA/rtrs: Do not reset hb_missed_max after re-connection Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 16/20] RDMA/rtrs-srv: Duplicated session name is not allowed Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 17/20] RDMA/rtrs-srv: Fix memory leak of unfreed rtrs_srv_stats object Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 18/20] RDMA/rtrs-srv: Fix memory leak when having multiple sessions Jack Wang
2021-05-28 11:30 ` [PATCHv3 for-next 19/20] RDMA/rtrs-clt: Check if the queue_depth has changed during a reconnection Jack Wang
2021-05-28 11:30 ` Jack Wang [this message]
2021-05-28 23:53 ` [PATCHv3 for-next 00/20] RTRS update for 5.14 Jason Gunthorpe

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=20210528113018.52290-21-jinpu.wang@ionos.com \
    --to=jinpu.wang@ionos.com \
    --cc=bvanassche@acm.org \
    --cc=dledford@redhat.com \
    --cc=gi-oh.kim@cloud.ionos.com \
    --cc=gi-oh.kim@ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.