]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
rdma: Fix the error of accessing string variable outside the lifecycle
authorwenglianfa <wenglianfa@huawei.com>
Fri, 29 Dec 2023 06:52:41 +0000 (14:52 +0800)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 8 Jan 2024 16:45:17 +0000 (08:45 -0800)
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>
rdma/res-cmid.c
rdma/res-cq.c
rdma/res-ctx.c
rdma/res-mr.c
rdma/res-pd.c
rdma/res-qp.c
rdma/res-srq.c
rdma/stat.c

index 8b6b349798f9fa853dac14c1b442da66a8354a6e..17a89cc4c6c21ad0b52ded2e0e81194df6acc294 100644 (file)
@@ -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;
index 420e935ac9266f47d704696dfc99451e044e5b67..0cab3fe0430083ef73d50f664d64d43787d6b4aa 100644 (file)
@@ -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;
index 0a84d01693270e7fe6aac9a9447146e662be69e5..235c837ac2af9b668e2ffd6e0921723d06939da7 100644 (file)
@@ -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;
index 693d98c142b664711c2f3363b97a9c1c38cff1ae..f6c2534aab5f95ebdb4554d5adbd55ae04ebdcc2 100644 (file)
@@ -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;
index 40a3f9bd561da488d95e2378ba69bf013326fbee..8b9f7aa68b429c46d6357bb8aeeb24fc521adb1e 100644 (file)
@@ -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;
index 145292aa375fc9392f855a7d7523c41f685c00dc..65ff54ab729f879fe5c46f91801674ee888b1f92 100644 (file)
@@ -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;
index 1d35900af7d13a4199d2c8cc9982285fac378e89..8ab2538ae93f6ddb4fac60513a47fff7b0484fd3 100644 (file)
@@ -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;
index 46ed1765179053b656ce6a4d1bf4e37ee39158c8..bf78f7cc77edc22cc633b1652ded98e4f57cae23 100644 (file)
@@ -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;