From: Denis Sergeev <denserg.edu@gmail.com>
To: dev@dpdk.org
Cc: stephen@networkplumber.org, Denis Sergeev <denserg.edu@gmail.com>
Subject: [PATCH v2] net/af_packet: fix qpairs argument upper bound check
Date: Wed, 3 Jun 2026 20:08:11 +0300 [thread overview]
Message-ID: <20260603170812.212262-1-denserg.edu@gmail.com> (raw)
In-Reply-To: <20260603044228.117357-1-denserg.edu@gmail.com>
The qpairs vdev argument was parsed with atoi(), which does no
validation: trailing garbage is ignored and a negative input such
as "-1" wraps to UINT_MAX when stored in the unsigned qpairs field,
passing the existing "< 1" check and reaching rte_pmd_init_internals()
as nb_queues. This causes excessive socket and memory allocation in
the per-queue loop.
Parse the value with strtoul() and reject non-numeric input, trailing
characters, negative values and values outside the
[1, RTE_MAX_QUEUES_PER_PORT] range.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: ccd37d341e8d ("net/af_packet: remove queue number limitation")
Signed-off-by: Denis Sergeev <denserg.edu@gmail.com>
---
v2:
* Replace atoi() with strtoul() and validate the parsed value
drivers/net/af_packet/rte_eth_af_packet.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 8303ff5ca9..b7758a5c75 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -1168,13 +1168,20 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
pair = &kvlist->pairs[k_idx];
if (strstr(pair->key, ETH_AF_PACKET_NUM_Q_ARG) != NULL) {
- qpairs = atoi(pair->value);
- if (qpairs < 1) {
+ char *endptr;
+ unsigned long num;
+
+ errno = 0;
+ num = strtoul(pair->value, &endptr, 10);
+ if (errno != 0 || endptr == pair->value ||
+ *endptr != '\0' || pair->value[0] == '-' ||
+ num < 1 || num > RTE_MAX_QUEUES_PER_PORT) {
PMD_LOG(ERR,
"%s: invalid qpairs value",
name);
return -1;
}
+ qpairs = num;
continue;
}
if (strstr(pair->key, ETH_AF_PACKET_BLOCKSIZE_ARG) != NULL) {
--
2.50.1
next prev parent reply other threads:[~2026-06-03 17:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 4:42 [PATCH] net/af_packet: fix qpairs argument upper bound check Denis Sergeev
2026-06-03 15:27 ` Stephen Hemminger
2026-06-03 17:08 ` Denis Sergeev [this message]
2026-06-03 18:13 ` [PATCH] net/af_packet: fix parsing of numeric device args 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=20260603170812.212262-1-denserg.edu@gmail.com \
--to=denserg.edu@gmail.com \
--cc=dev@dpdk.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