aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwenglianfa <wenglianfa@huawei.com>2023-12-29 14:52:41 +0800
committerStephen Hemminger <stephen@networkplumber.org>2024-01-08 08:45:17 -0800
commit3a882b6b4e0ee8c7cfd11176d36a98d30fc449d3 (patch)
tree0e05251e280032b1c644ab12365b472792f29a14
parenta903854bad1c5121b35f0f22af18c66a847d20de (diff)
downloadiproute2-next-3a882b6b4e0ee8c7cfd11176d36a98d30fc449d3.tar.gz
rdma: Fix the error of accessing string variable outside the lifecycle
All these SPRINT_BUF(b) definitions are inside the 'if' block, but accessed outside the 'if' block through the pointers 'comm'. This leads to empty 'comm' attribute when querying resource information. So move the definitions to the beginning of the functions to extend their life cycle. Before: $ rdma res show srq dev hns_0 srqn 0 type BASIC lqpn 18 pdn 5 pid 7775 comm After: $ rdma res show srq dev hns_0 srqn 0 type BASIC lqpn 18 pdn 5 pid 7775 comm ib_send_bw Fixes: 1808f002dfdd ("lib/fs: fix memory leak in get_task_name()") Signed-off-by: wenglianfa <wenglianfa@huawei.com> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com> Reviewed-by: Petr Machata <petrm@nvidia.com> Acked-by: Andrea Claudi <aclaudi@redhat.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--rdma/res-cmid.c3
-rw-r--r--rdma/res-cq.c3
-rw-r--r--rdma/res-ctx.c3
-rw-r--r--rdma/res-mr.c3
-rw-r--r--rdma/res-pd.c3
-rw-r--r--rdma/res-qp.c3
-rw-r--r--rdma/res-srq.c3
-rw-r--r--rdma/stat.c3
8 files changed, 8 insertions, 16 deletions
diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c
index 8b6b34979..17a89cc4c 100644
--- a/rdma/res-cmid.c
+++ b/rdma/res-cmid.c
@@ -99,6 +99,7 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
uint32_t lqpn = 0, ps;
uint32_t cm_idn = 0;
char *comm = NULL;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
!nla_line[RDMA_NLDEV_ATTR_RES_PS])
@@ -156,8 +157,6 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-cq.c b/rdma/res-cq.c
index 420e935ac..0cab3fe04 100644
--- a/rdma/res-cq.c
+++ b/rdma/res-cq.c
@@ -63,6 +63,7 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
uint32_t cqn = 0;
uint64_t users;
uint32_t cqe;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
!nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
@@ -84,8 +85,6 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-ctx.c b/rdma/res-ctx.c
index 0a84d0169..235c837ac 100644
--- a/rdma/res-ctx.c
+++ b/rdma/res-ctx.c
@@ -13,13 +13,12 @@ static int res_ctx_line(struct rd *rd, const char *name, int idx,
char *comm = NULL;
uint32_t ctxn = 0;
uint32_t pid = 0;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
return MNL_CB_ERROR;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-mr.c b/rdma/res-mr.c
index 693d98c14..f6c2534aa 100644
--- a/rdma/res-mr.c
+++ b/rdma/res-mr.c
@@ -31,6 +31,7 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
uint32_t pdn = 0;
uint32_t mrn = 0;
uint32_t pid = 0;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN])
return MNL_CB_ERROR;
@@ -48,8 +49,6 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-pd.c b/rdma/res-pd.c
index 40a3f9bd5..8b9f7aa68 100644
--- a/rdma/res-pd.c
+++ b/rdma/res-pd.c
@@ -16,6 +16,7 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
uint32_t pid = 0;
uint32_t pdn = 0;
uint64_t users;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
return MNL_CB_ERROR;
@@ -34,8 +35,6 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-qp.c b/rdma/res-qp.c
index 145292aa3..65ff54ab7 100644
--- a/rdma/res-qp.c
+++ b/rdma/res-qp.c
@@ -84,6 +84,7 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
uint32_t port = 0, pid = 0;
uint32_t pdn = 0;
char *comm = NULL;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN] ||
!nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] ||
@@ -144,8 +145,6 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/res-srq.c b/rdma/res-srq.c
index 1d35900af..8ab2538ae 100644
--- a/rdma/res-srq.c
+++ b/rdma/res-srq.c
@@ -183,13 +183,12 @@ static int res_srq_line(struct rd *rd, const char *name, int idx,
char qp_str[MAX_QP_STR_LEN] = {};
char *comm = NULL;
uint8_t type = 0;
+ SPRINT_BUF(b);
if (!nla_line[RDMA_NLDEV_ATTR_RES_SRQN])
return MNL_CB_ERROR;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;
diff --git a/rdma/stat.c b/rdma/stat.c
index 46ed17651..bf78f7cc7 100644
--- a/rdma/stat.c
+++ b/rdma/stat.c
@@ -222,6 +222,7 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
struct nlattr *hwc_table, *qp_table;
struct nlattr *nla_entry;
const char *comm = NULL;
+ SPRINT_BUF(b);
bool isfirst;
int err;
@@ -247,8 +248,6 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
return MNL_CB_OK;
if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
- SPRINT_BUF(b);
-
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b, sizeof(b)))
comm = b;