All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	stable@dpdk.org, Tetsuya Mukawa <mtetsuyah@gmail.com>,
	Ferruh Yigit <ferruh.yigit@amd.com>
Subject: [PATCH v10 3/6] net/null: validate the numeric devargs
Date: Sun,  1 Feb 2026 09:17:34 -0800	[thread overview]
Message-ID: <20260201171938.89492-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20260201171938.89492-1-stephen@networkplumber.org>

The driver was not correctly validating the arguments for packet_size,
packet_copy, and no_rx. The original parsing had several issues:
- Empty strings were not rejected
- Trailing non-numeric characters were silently ignored
- Large values could wrap around causing unexpected behavior

Add a common helper function get_unsigned_arg() that properly validates
numeric arguments by checking for empty input, ensuring the entire
string is consumed, and enforcing appropriate maximum values for each
parameter.

Fixes: 4df90194f2a2 ("net/null: prefer unsigned int")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/null/rte_eth_null.c | 59 +++++++++++++++------------------
 1 file changed, 26 insertions(+), 33 deletions(-)

diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index f2ffdc2b2b..0b6c9577cd 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -603,56 +603,49 @@ eth_dev_null_create(struct rte_vdev_device *dev, struct pmd_options *args)
 	return 0;
 }
 
-static inline int
-get_packet_size_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
+static int
+get_unsigned_arg(const char *str, unsigned int *retval,
+		 unsigned int maxval)
 {
-	const char *a = value;
-	unsigned int *packet_size = extra_args;
+	char *endp = NULL;
+	unsigned long val;
 
-	if ((value == NULL) || (extra_args == NULL))
+	if (str == NULL || retval == NULL)
 		return -EINVAL;
 
-	*packet_size = (unsigned int)strtoul(a, NULL, 0);
-	if (*packet_size == UINT_MAX)
-		return -1;
+	if (*str == '\0')
+		return -EINVAL; /* empty string */
 
+	val = strtoul(str, &endp, 0);
+	if (*endp != '\0')
+		return -EINVAL; /* non-numeric character */
+
+	if (val > maxval)
+		return -ERANGE;
+
+	*retval = val;
 	return 0;
 }
 
-static inline int
-get_packet_copy_arg(const char *key __rte_unused,
+static int
+get_packet_size_arg(const char *key __rte_unused,
 		const char *value, void *extra_args)
 {
-	const char *a = value;
-	unsigned int *packet_copy = extra_args;
-
-	if ((value == NULL) || (extra_args == NULL))
-		return -EINVAL;
-
-	*packet_copy = (unsigned int)strtoul(a, NULL, 0);
-	if (*packet_copy == UINT_MAX)
-		return -1;
+	return get_unsigned_arg(value, extra_args, UINT16_MAX);
+}
 
-	return 0;
+static int
+get_packet_copy_arg(const char *key __rte_unused,
+		const char *value, void *extra_args)
+{
+	return get_unsigned_arg(value, extra_args, UINT32_MAX);
 }
 
 static int
 get_packet_no_rx_arg(const char *key __rte_unused,
 		const char *value, void *extra_args)
 {
-	const char *a = value;
-	unsigned int no_rx;
-
-	if (value == NULL || extra_args == NULL)
-		return -EINVAL;
-
-	no_rx = (unsigned int)strtoul(a, NULL, 0);
-	if (no_rx != 0 && no_rx != 1)
-		return -1;
-
-	*(unsigned int *)extra_args = no_rx;
-	return 0;
+	return get_unsigned_arg(value, extra_args, 1);
 }
 
 static int
-- 
2.51.0


  parent reply	other threads:[~2026-02-01 17:20 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-04 22:25 [PATCH] test: add a test for null PMD Stephen Hemminger
2026-01-05 14:49 ` Marat Khalili
2026-01-05 17:38   ` Stephen Hemminger
2026-01-06 16:47 ` [PATCH v2 0/2] net/null: add a test Stephen Hemminger
2026-01-06 16:47   ` [PATCH v2 1/2] test: add a test for null PMD Stephen Hemminger
2026-01-06 17:40     ` Marat Khalili
2026-01-06 18:01       ` Stephen Hemminger
2026-01-06 16:47   ` [PATCH v2 2/2] net/null: revise info_get Stephen Hemminger
2026-01-08 20:40 ` [PATCH v3 0/3] test: new test for null PMD Stephen Hemminger
2026-01-08 20:40   ` [PATCH v3 1/3] net/null: cleanup info_get Stephen Hemminger
2026-01-08 20:40   ` [PATCH v3 2/3] test: allow larger packet sizes Stephen Hemminger
2026-01-09 15:00     ` Morten Brørup
2026-01-10 17:21       ` Stephen Hemminger
2026-01-08 20:40   ` [PATCH v3 3/3] test: add a test for null PMD Stephen Hemminger
2026-01-09  1:21     ` Stephen Hemminger
2026-01-10 17:22 ` [PATCH v4 0/3] null pmd minor cleanup and add test Stephen Hemminger
2026-01-10 17:22   ` [PATCH v4 1/3] net/null: cleanup info_get Stephen Hemminger
2026-01-10 17:22   ` [PATCH v4 2/3] test: generate larger packet bursts Stephen Hemminger
2026-01-10 17:22   ` [PATCH v4 3/3] test: add a test for null PMD Stephen Hemminger
2026-01-12  0:56   ` [PATCH v4 0/3] null pmd minor cleanup and add test Stephen Hemminger
2026-01-14 18:30 ` [PATCH v5 0/3] test: add null PMD test suite Stephen Hemminger
2026-01-14 18:30   ` [PATCH v5 1/3] net/null: cleanup info_get Stephen Hemminger
2026-01-14 18:30   ` [PATCH v5 2/3] test: generate larger packet bursts Stephen Hemminger
2026-01-14 18:30   ` [PATCH v5 3/3] test: add a test for null PMD Stephen Hemminger
2026-01-18 16:50 ` [PATCH v6 0/3] test: add null PMD test suite Stephen Hemminger
2026-01-18 16:50   ` [PATCH v6 1/3] net/null: cleanup info response Stephen Hemminger
2026-01-18 16:50   ` [PATCH v6 2/3] test: generate larger packet bursts Stephen Hemminger
2026-01-18 16:50   ` [PATCH v6 3/3] test: add a test for null PMD Stephen Hemminger
2026-01-25 20:23 ` [PATCH v7 0/5] net/null: improvements and bug fixes Stephen Hemminger
2026-01-25 20:23   ` [PATCH v7 1/5] net/null: cleanup info response Stephen Hemminger
2026-01-25 20:23   ` [PATCH v7 2/5] test: generate larger packet bursts Stephen Hemminger
2026-01-25 20:23   ` [PATCH v7 3/5] test: add a test for null PMD Stephen Hemminger
2026-01-25 20:23   ` [PATCH v7 4/5] net/null: add check for pool vs packet size Stephen Hemminger
2026-01-25 20:23   ` [PATCH v7 5/5] net/null: check packet size argument Stephen Hemminger
2026-01-28 19:00 ` [PATCH v8 0/5] net/null: improvements and bug fixes Stephen Hemminger
2026-01-28 19:00   ` [PATCH v8 1/5] net/null: cleanup info response Stephen Hemminger
2026-01-28 19:00   ` [PATCH v8 2/5] test: generate larger packet bursts Stephen Hemminger
2026-01-28 19:00   ` [PATCH v8 3/5] test: add a test for null PMD Stephen Hemminger
2026-01-28 19:00   ` [PATCH v8 4/5] net/null: add check for pool vs packet size Stephen Hemminger
2026-01-28 19:00   ` [PATCH v8 5/5] net/null: check packet size argument Stephen Hemminger
2026-01-29 20:25 ` [PATCH v9 0/5] net/null: improvements and bug fixes Stephen Hemminger
2026-01-29 20:25   ` [PATCH v9 1/5] net/null: cleanup info response Stephen Hemminger
2026-01-29 20:25   ` [PATCH v9 2/5] net/null: validate the numeric devargs Stephen Hemminger
2026-01-29 20:25   ` [PATCH v9 3/5] net/null: remove redundant argument validation Stephen Hemminger
2026-01-29 20:25   ` [PATCH v9 4/5] test: support larger packet sizes in burst generator Stephen Hemminger
2026-01-29 20:25   ` [PATCH v9 5/5] test: add a test for null PMD Stephen Hemminger
2026-02-01 17:17 ` [PATCH v10 0/6] net/null: bug fixes and improvements Stephen Hemminger
2026-02-01 17:17   ` [PATCH v10 1/6] net/null: fix missing mbuf leakage in the copy transmit Stephen Hemminger
2026-02-01 17:17   ` [PATCH v10 2/6] net/null: cleanup info response Stephen Hemminger
2026-02-01 17:17   ` Stephen Hemminger [this message]
2026-02-01 17:17   ` [PATCH v10 4/6] net/null: remove redundant argument validation Stephen Hemminger
2026-02-01 17:17   ` [PATCH v10 5/6] test: support larger packet sizes in burst generator Stephen Hemminger
2026-02-01 17:17   ` [PATCH v10 6/6] test: add a test for null PMD Stephen Hemminger
2026-02-02 22:16 ` [PATCH v11 0/7] net/null: bug fixes and improvements Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 1/7] net/null: fix missing mbuf leakage in the copy transmit Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 2/7] net/null: cleanup info response Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 3/7] net/null: validate the numeric devargs Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 4/7] net/null: remove redundant argument validation Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 5/7] test: support larger packet sizes in burst generator Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 6/7] test: add a test for null PMD Stephen Hemminger
2026-02-02 22:16   ` [PATCH v11 7/7] net/null: add VLAN insert and strip offload support 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=20260201171938.89492-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=mtetsuyah@gmail.com \
    --cc=stable@dpdk.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.