patch 'examples/l3fwd-power: fix options parsing overflow' has been queued to stable release 23.11.3
Xueming Li
xuemingl at nvidia.com
Sat Dec 7 08:59:42 CET 2024
Hi,
FYI, your patch has been queued to stable release 23.11.3
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/10/24. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=23.11-staging
This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=23.11-staging&id=d24b14e13169592f838b16a8ec12d6c37e1c537e
Thanks.
Xueming Li <xuemingl at nvidia.com>
---
>From d24b14e13169592f838b16a8ec12d6c37e1c537e Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong at huawei.com>
Date: Mon, 11 Nov 2024 10:25:49 +0800
Subject: [PATCH] examples/l3fwd-power: fix options parsing overflow
Cc: Xueming Li <xuemingl at nvidia.com>
[ upstream commit 0bc4795d5994459a3d261afd7f843eb0cabdecf5 ]
Many variables are 'uint32_t', like, 'pause_duration', 'scale_freq_min'
and so on. They use parse_int() to parse it from command line.
But overflow problem occurs when this function return.
Fixes: 59f2853c4cae ("examples/l3fwd_power: add configuration options")
Signed-off-by: Huisong Li <lihuisong at huawei.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
Acked-by: Sivaprasad Tummala <sivaprasad.tummala at amd.com>
---
examples/l3fwd-power/main.c | 41 +++++++++++++++++++------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 996ac6dc56..7640b5a9a3 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -1523,8 +1523,12 @@ print_usage(const char *prgname)
prgname);
}
+/*
+ * Caller must give the right upper limit so as to ensure receiver variable
+ * doesn't overflow.
+ */
static int
-parse_int(const char *opt)
+parse_uint(const char *opt, uint32_t max, uint32_t *res)
{
char *end = NULL;
unsigned long val;
@@ -1534,23 +1538,15 @@ parse_int(const char *opt)
if ((opt[0] == '\0') || (end == NULL) || (*end != '\0'))
return -1;
- return val;
-}
-
-static int parse_max_pkt_len(const char *pktlen)
-{
- char *end = NULL;
- unsigned long len;
-
- /* parse decimal string */
- len = strtoul(pktlen, &end, 10);
- if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
+ if (val > max) {
+ RTE_LOG(ERR, L3FWD_POWER, "%s parameter shouldn't exceed %u.\n",
+ opt, max);
return -1;
+ }
- if (len == 0)
- return -1;
+ *res = val;
- return len;
+ return 0;
}
static int
@@ -1897,8 +1893,9 @@ parse_args(int argc, char **argv)
if (!strncmp(lgopts[option_index].name,
CMD_LINE_OPT_MAX_PKT_LEN,
sizeof(CMD_LINE_OPT_MAX_PKT_LEN))) {
+ if (parse_uint(optarg, UINT32_MAX, &max_pkt_len) != 0)
+ return -1;
printf("Custom frame size is configured\n");
- max_pkt_len = parse_max_pkt_len(optarg);
}
if (!strncmp(lgopts[option_index].name,
@@ -1911,29 +1908,33 @@ parse_args(int argc, char **argv)
if (!strncmp(lgopts[option_index].name,
CMD_LINE_OPT_MAX_EMPTY_POLLS,
sizeof(CMD_LINE_OPT_MAX_EMPTY_POLLS))) {
+ if (parse_uint(optarg, UINT32_MAX, &max_empty_polls) != 0)
+ return -1;
printf("Maximum empty polls configured\n");
- max_empty_polls = parse_int(optarg);
}
if (!strncmp(lgopts[option_index].name,
CMD_LINE_OPT_PAUSE_DURATION,
sizeof(CMD_LINE_OPT_PAUSE_DURATION))) {
+ if (parse_uint(optarg, UINT32_MAX, &pause_duration) != 0)
+ return -1;
printf("Pause duration configured\n");
- pause_duration = parse_int(optarg);
}
if (!strncmp(lgopts[option_index].name,
CMD_LINE_OPT_SCALE_FREQ_MIN,
sizeof(CMD_LINE_OPT_SCALE_FREQ_MIN))) {
+ if (parse_uint(optarg, UINT32_MAX, &scale_freq_min) != 0)
+ return -1;
printf("Scaling frequency minimum configured\n");
- scale_freq_min = parse_int(optarg);
}
if (!strncmp(lgopts[option_index].name,
CMD_LINE_OPT_SCALE_FREQ_MAX,
sizeof(CMD_LINE_OPT_SCALE_FREQ_MAX))) {
+ if (parse_uint(optarg, UINT32_MAX, &scale_freq_max) != 0)
+ return -1;
printf("Scaling frequency maximum configured\n");
- scale_freq_max = parse_int(optarg);
}
break;
--
2.34.1
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2024-12-06 23:26:44.938557317 +0800
+++ 0024-examples-l3fwd-power-fix-options-parsing-overflow.patch 2024-12-06 23:26:43.903044828 +0800
@@ -1 +1 @@
-From 0bc4795d5994459a3d261afd7f843eb0cabdecf5 Mon Sep 17 00:00:00 2001
+From d24b14e13169592f838b16a8ec12d6c37e1c537e Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 0bc4795d5994459a3d261afd7f843eb0cabdecf5 ]
@@ -11 +13,0 @@
-Cc: stable at dpdk.org
@@ -22 +24 @@
-index 272e069207..7bc524aa16 100644
+index 996ac6dc56..7640b5a9a3 100644
@@ -25 +27 @@
-@@ -1520,8 +1520,12 @@ print_usage(const char *prgname)
+@@ -1523,8 +1523,12 @@ print_usage(const char *prgname)
@@ -39 +41 @@
-@@ -1531,23 +1535,15 @@ parse_int(const char *opt)
+@@ -1534,23 +1538,15 @@ parse_int(const char *opt)
@@ -69 +71 @@
-@@ -1894,8 +1890,9 @@ parse_args(int argc, char **argv)
+@@ -1897,8 +1893,9 @@ parse_args(int argc, char **argv)
@@ -80 +82 @@
-@@ -1908,29 +1905,33 @@ parse_args(int argc, char **argv)
+@@ -1911,29 +1908,33 @@ parse_args(int argc, char **argv)
More information about the stable
mailing list