[PATCH] sched: fix subport free on RED/PIE config failure

Alexander.Chesnokov at kaspersky.com Alexander.Chesnokov at kaspersky.com
Wed Nov 25 06:30:21 CET 2026


From: Alexander Chesnokov <Alexander.Chesnokov at kaspersky.com>

rte_sched_subport_config() registers the newly allocated subport in
port->subports[] right after the allocation, but assigns the queue
array pointers s->queue and s->queue_array only later in the
function, after the CMAN configuration block. If rte_red_config_init()
or rte_pie_config_init() rejects the parameters, the function returns
before reaching the assignments, and the failure path frees the port
through rte_sched_free_memory() -> rte_sched_subport_free(), which
drains enqueued mbufs by dereferencing subport->queue and
subport->queue_array. Both pointers are still NULL at that point and
the drain loop faults reading the queue pointers.

The PIE tail queue threshold check rejects the parameters without
freeing anything. The half-initialized subport then stays reachable
through port->subports[], and a later rte_sched_port_free() faults
in the same drain loop.

Move the CMAN configuration after the queue base calculation and the
array base assignments. Those are pure functions of the subport
parameters and the subport allocation, so nothing changes for
configurations that pass. On the failure path the subport is freed
with the array pointers referencing the zeroed subport memory, the
drain loop finds empty queues and completes safely.

Add sched_autotest cases verifying that rte_sched_subport_config()
rejects invalid RED (min_th == max_th) and invalid PIE (qdelay_ref
== 0, tailq_th > qsize) parameters without crashing, and that a
later rte_sched_port_free() completes safely on the subport that a
rejected PIE tail queue threshold leaves half-initialized. Check
that a valid RED configuration still succeeds.

Freeing the whole port on a configuration error, which leaves the
caller with a dangling port pointer, is a separate problem and is
not changed here.

Fixes: ce7c4fd7c2ac ("sched: add pipe config to subport level")
Cc: stable at dpdk.org

Signed-off-by: Alexander Chesnokov <Alexander.Chesnokov at kaspersky.com>
---

Cc: jasvinder.singh at intel.com

 app/test/test_sched.c | 69 +++++++++++++++++++++++++++++++++++++++++++
 lib/sched/rte_sched.c | 24 +++++++--------
 2 files changed, 81 insertions(+), 12 deletions(-)

diff --git a/app/test/test_sched.c b/app/test/test_sched.c
index 96b48f1897..69b1bf59dd 100644
--- a/app/test/test_sched.c
+++ b/app/test/test_sched.c
@@ -210,6 +210,75 @@ test_sched(void)
 
 	rte_sched_port_free(port);
 
+	static struct rte_sched_cman_params cman_red_bad = {
+		.cman_mode = RTE_SCHED_CMAN_RED,
+		.red_params[0][RTE_COLOR_GREEN] = {
+			.min_th = 1, .max_th = 1, .maxp_inv = 10, .wq_log2 = 9,
+		},
+	};
+	static struct rte_sched_cman_params cman_pie_bad = {
+		.cman_mode = RTE_SCHED_CMAN_PIE,
+		.pie_params[0] = {
+			.qdelay_ref = 0,
+			.dp_update_interval = 100,
+			.max_burst = 10,
+			.tailq_th = 1,
+		},
+	};
+	static struct rte_sched_cman_params cman_pie_tailq_bad = {
+		.cman_mode = RTE_SCHED_CMAN_PIE,
+		.pie_params[0] = {
+			.qdelay_ref = 10,
+			.dp_update_interval = 100,
+			.max_burst = 10,
+			.tailq_th = 64,
+		},
+	};
+	static struct rte_sched_cman_params cman_red_ok = {
+		.cman_mode = RTE_SCHED_CMAN_RED,
+		.red_params[0][RTE_COLOR_GREEN] = {
+			.min_th = 1, .max_th = 1023, .maxp_inv = 10, .wq_log2 = 9,
+		},
+	};
+	struct rte_sched_subport_params sp = subport_param[0];
+
+	port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8;
+
+	/* Invalid RED (min_th == max_th) is rejected without crashing */
+	sp.cman_params = &cman_red_bad;
+	port = rte_sched_port_config(&port_param);
+	TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
+	err = rte_sched_subport_config(port, SUBPORT, &sp, 0);
+	TEST_ASSERT_FAIL(err, "Invalid RED configuration accepted\n");
+	port = NULL;
+
+	/* Invalid PIE (qdelay_ref == 0) is rejected without crashing */
+	sp.cman_params = &cman_pie_bad;
+	port = rte_sched_port_config(&port_param);
+	TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
+	err = rte_sched_subport_config(port, SUBPORT, &sp, 0);
+	TEST_ASSERT_FAIL(err, "Invalid PIE configuration accepted\n");
+	port = NULL;
+
+	/*
+	 * PIE tailq threshold above qsize keeps the half-initialized
+	 * subport registered; freeing the port must not fault
+	 */
+	sp.cman_params = &cman_pie_tailq_bad;
+	port = rte_sched_port_config(&port_param);
+	TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
+	err = rte_sched_subport_config(port, SUBPORT, &sp, 0);
+	TEST_ASSERT_FAIL(err, "Invalid PIE tailq threshold accepted\n");
+	rte_sched_port_free(port);
+
+	/* Valid RED configuration succeeds and the port frees cleanly */
+	sp.cman_params = &cman_red_ok;
+	port = rte_sched_port_config(&port_param);
+	TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
+	err = rte_sched_subport_config(port, SUBPORT, &sp, 0);
+	TEST_ASSERT_SUCCESS(err, "Valid RED configuration rejected\n");
+	rte_sched_port_free(port);
+
 	return 0;
 }
 
diff --git a/lib/sched/rte_sched.c b/lib/sched/rte_sched.c
index daa31e8b99..b49771f285 100644
--- a/lib/sched/rte_sched.c
+++ b/lib/sched/rte_sched.c
@@ -1280,18 +1280,6 @@ rte_sched_subport_config(struct rte_sched_port *port,
 		/* TC oversubscription is enabled by default */
 		s->tc_ov_enabled = 1;
 
-		if (params->cman_params != NULL) {
-			s->cman_enabled = true;
-			status = rte_sched_cman_config(port, s, params, n_subports);
-			if (status) {
-				SCHED_LOG(NOTICE,
-					"%s: CMAN configuration fails", __func__);
-				return status;
-			}
-		} else {
-			s->cman_enabled = false;
-		}
-
 		/* Scheduling loop detection */
 		s->pipe_loop = RTE_SCHED_PIPE_INVALID;
 		s->pipe_exhaustion = 0;
@@ -1321,6 +1309,18 @@ rte_sched_subport_config(struct rte_sched_port *port,
 			(s->memory + rte_sched_subport_get_array_base(params,
 			e_RTE_SCHED_SUBPORT_ARRAY_QUEUE_ARRAY));
 
+		if (params->cman_params != NULL) {
+			s->cman_enabled = true;
+			status = rte_sched_cman_config(port, s, params, n_subports);
+			if (status) {
+				SCHED_LOG(NOTICE,
+					"%s: CMAN configuration fails", __func__);
+				return status;
+			}
+		} else {
+			s->cman_enabled = false;
+		}
+
 		/* Pipe profile table */
 		rte_sched_subport_config_pipe_profile_table(s, params,
 							    port->rate);
-- 
2.53.0



More information about the stable mailing list