[PATCH 2/3] sched: reject API calls on unconfigured subport
Alexander.Chesnokov at kaspersky.com
Alexander.Chesnokov at kaspersky.com
Fri Nov 27 05:40:55 CET 2026
From: Alexander Chesnokov <Alexander.Chesnokov at kaspersky.com>
rte_sched_pipe_config(), rte_sched_subport_read_stats(),
rte_sched_queue_read_stats(), rte_sched_subport_tc_ov_config() and
rte_sched_subport_pipe_profile_add() dereference the subport slot
of the port without checking it. A subport whose
rte_sched_subport_config() has not completed leaves the slot NULL,
and the call crashes on the NULL pointer. The pipe profile add
also accepts subport_id equal to the number of subports and reads
one slot past the end of the array.
Return -EINVAL for an unconfigured subport in these calls and fix
the subport id check in the pipe profile add. Statistics of the
configured subports of the same port keep working, so a failed
subport configuration no longer poisons the statistics of the
whole port.
Fixes: 34a90f86657c ("sched: modify pipe functions for config flexibility")
Fixes: ce7c4fd7c2ac ("sched: add pipe config to subport level")
Fixes: f5e60154adec ("sched: enable traffic class oversubscription conditionally")
Cc: stable at dpdk.org
Signed-off-by: Alexander Chesnokov <Alexander.Chesnokov at kaspersky.com>
---
lib/sched/rte_sched.c | 27 ++++++++++++++++++++++++++-
lib/sched/rte_sched.h | 9 ++++++---
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/lib/sched/rte_sched.c b/lib/sched/rte_sched.c
index f7df0886c4..861efb4b37 100644
--- a/lib/sched/rte_sched.c
+++ b/lib/sched/rte_sched.c
@@ -1159,6 +1159,11 @@ rte_sched_subport_tc_ov_config(struct rte_sched_port *port,
}
s = port->subports[subport_id];
+ if (s == NULL) {
+ SCHED_LOG(ERR,
+ "%s: Subport is not configured", __func__);
+ return -EINVAL;
+ }
s->tc_ov_enabled = tc_ov_enable ? 1 : 0;
return 0;
@@ -1378,6 +1383,11 @@ rte_sched_pipe_config(struct rte_sched_port *port,
}
s = port->subports[subport_id];
+ if (s == NULL) {
+ SCHED_LOG(ERR,
+ "%s: Subport is not configured", __func__);
+ return -EINVAL;
+ }
if (pipe_id >= s->n_pipes_per_subport_enabled) {
SCHED_LOG(ERR,
"%s: Incorrect value for parameter pipe id", __func__);
@@ -1483,13 +1493,18 @@ rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
}
/* Subport id not exceeds the max limit */
- if (subport_id > port->n_subports_per_port) {
+ if (subport_id >= port->n_subports_per_port) {
SCHED_LOG(ERR,
"%s: Incorrect value for subport id", __func__);
return -EINVAL;
}
s = port->subports[subport_id];
+ if (s == NULL) {
+ SCHED_LOG(ERR,
+ "%s: Subport is not configured", __func__);
+ return -EINVAL;
+ }
/* Pipe profiles exceeds the max limit */
if (s->n_pipe_profiles >= s->n_max_pipe_profiles) {
@@ -1683,6 +1698,11 @@ rte_sched_subport_read_stats(struct rte_sched_port *port,
}
s = port->subports[subport_id];
+ if (s == NULL) {
+ SCHED_LOG(ERR,
+ "%s: Subport is not configured", __func__);
+ return -EINVAL;
+ }
/* Copy subport stats and clear */
memcpy(stats, &s->stats, sizeof(struct rte_sched_subport_stats));
@@ -1734,6 +1754,11 @@ rte_sched_queue_read_stats(struct rte_sched_port *port,
subport_id = (queue_id >> subport_qmask) & (port->n_subports_per_port - 1);
s = port->subports[subport_id];
+ if (s == NULL) {
+ SCHED_LOG(ERR,
+ "%s: Subport is not configured", __func__);
+ return -EINVAL;
+ }
subport_qindex = ((1 << subport_qmask) - 1) & queue_id;
q = s->queue + subport_qindex;
qe = s->queue_extra + subport_qindex;
diff --git a/lib/sched/rte_sched.h b/lib/sched/rte_sched.h
index b839392250..53798ce3ee 100644
--- a/lib/sched/rte_sched.h
+++ b/lib/sched/rte_sched.h
@@ -420,7 +420,8 @@ rte_sched_subport_config(struct rte_sched_port *port,
* rte_sched_port_free() as usual. The subport whose configuration
* failed stays unconfigured and the call can be repeated with
* corrected parameters. The subports configured before the failed
- * call keep their configuration, statistics and queued packets.
+ * call keep their configuration, statistics and queued packets. A
+ * call on a subport that is not configured returns -EINVAL.
*/
int
rte_sched_pipe_config(struct rte_sched_port *port,
@@ -461,7 +462,8 @@ rte_sched_port_get_memory_footprint(struct rte_sched_port_params *port_params,
* where the oversubscription status for each of the subport traffic classes
* should be stored.
* @return
- * 0 upon success, error code otherwise
+ * 0 upon success, error code otherwise; -EINVAL if the subport
+ * is not configured
*/
int
rte_sched_subport_read_stats(struct rte_sched_port *port,
@@ -483,7 +485,8 @@ rte_sched_subport_read_stats(struct rte_sched_port *port,
* Pointer to pre-allocated variable where the current queue length
* should be stored.
* @return
- * 0 upon success, error code otherwise
+ * 0 upon success, error code otherwise; -EINVAL if the subport
+ * is not configured
*/
int
rte_sched_queue_read_stats(struct rte_sched_port *port,
--
2.53.0
More information about the stable
mailing list