netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Ido Kalir <idok@nvidia.com>, David Ahern <dsahern@gmail.com>,
	linux-netdev <netdev@vger.kernel.org>,
	RDMA mailing list <linux-rdma@vger.kernel.org>
Subject: [PATCH iproute2-rc] rdma: Fix statistics bind/unbing argument handling
Date: Sun, 14 Feb 2021 10:33:35 +0200	[thread overview]
Message-ID: <20210214083335.19558-1-leon@kernel.org> (raw)

From: Ido Kalir <idok@nvidia.com>

The dump isn't supported for the statistics bind/unbind commands
because they operate on specific QP counters. This is different
from query commands that can operate on many objects at the same
time.

Let's check the user input and ensure that arguments are valid.

Fixes: a6d0773ebecc ("rdma: Add stat manual mode support")
Signed-off-by: Ido Kalir <idok@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 rdma/rdma.h  |  1 +
 rdma/stat.c  | 21 +++++++++++++++++++++
 rdma/utils.c |  7 +++++++
 3 files changed, 29 insertions(+)

diff --git a/rdma/rdma.h b/rdma/rdma.h
index 735b1bf7..7f96c051 100644
--- a/rdma/rdma.h
+++ b/rdma/rdma.h
@@ -83,6 +83,7 @@ struct rd_cmd {
  * Parser interface
  */
 bool rd_no_arg(struct rd *rd);
+bool rd_is_multiarg(struct rd *rd);
 void rd_arg_inc(struct rd *rd);

 char *rd_argv(struct rd *rd);
diff --git a/rdma/stat.c b/rdma/stat.c
index 8d4b7a11..a6b6dfbf 100644
--- a/rdma/stat.c
+++ b/rdma/stat.c
@@ -455,6 +455,12 @@ static int stat_get_arg(struct rd *rd, const char *arg)
 		return -EINVAL;

 	rd_arg_inc(rd);
+
+	if (rd_is_multiarg(rd)){
+		pr_err("The parameter %s shouldn't include range\n", arg);
+		return -EINVAL;
+	}
+
 	value = strtol(rd_argv(rd), &endp, 10);
 	rd_arg_inc(rd);

@@ -476,6 +482,8 @@ static int stat_one_qp_bind(struct rd *rd)
 		return ret;

 	lqpn = stat_get_arg(rd, "lqpn");
+	if (lqpn < 0)
+		return lqpn;

 	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_SET,
 		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
@@ -490,6 +498,9 @@ static int stat_one_qp_bind(struct rd *rd)

 	if (rd_argc(rd)) {
 		cntn = stat_get_arg(rd, "cntn");
+		if (cntn < 0)
+			return cntn;
+
 		mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_COUNTER_ID,
 				 cntn);
 	}
@@ -560,13 +571,23 @@ static int stat_one_qp_unbind(struct rd *rd)
 	unsigned int portid;
 	uint32_t seq;

+	if (rd_no_arg(rd)) {
+		stat_help(rd);
+		return -EINVAL;
+	}
+
 	ret = rd_build_filter(rd, stat_valid_filters);
 	if (ret)
 		return ret;

 	cntn = stat_get_arg(rd, "cntn");
+	if (cntn < 0)
+		return cntn;
+
 	if (rd_argc(rd)) {
 		lqpn = stat_get_arg(rd, "lqpn");
+		if (lqpn < 0)
+			return lqpn;
 		return do_stat_qp_unbind_lqpn(rd, cntn, lqpn);
 	}

diff --git a/rdma/utils.c b/rdma/utils.c
index e25c3adf..bbfa23ba 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -47,6 +47,13 @@ bool rd_no_arg(struct rd *rd)
 	return rd_argc(rd) == 0;
 }

+bool rd_is_multiarg(struct rd *rd)
+{
+	if (!rd_argc(rd))
+		return false;
+	return strpbrk(rd_argv(rd), ",-") != NULL;
+}
+
 /*
  * Possible input:output
  * dev/port    | first port | is_dump_all
--
2.29.2


             reply	other threads:[~2021-02-14  8:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14  8:33 Leon Romanovsky [this message]
2021-02-15  3:26 ` [PATCH iproute2-rc] rdma: Fix statistics bind/unbing argument handling David Ahern
2021-02-15  5:40   ` Leon Romanovsky
2021-02-16  1:56     ` David Ahern
2021-02-16  6:16       ` Leon Romanovsky
2021-02-16 15:48         ` David Ahern
2021-02-18  8:44           ` Leon Romanovsky
2021-02-22 19:18             ` Stephen Hemminger

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=20210214083335.19558-1-leon@kernel.org \
    --to=leon@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=idok@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).