[v3,1/3] eal: fix uncheck lcore ID

Message ID 20250402122454.2148612-2-huangdengdui@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series fix the problem of dma-perf infinite loop |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dengdui Huang April 2, 2025, 12:24 p.m. UTC
The worker_id may come from user input.
So it is necessary to verify it.

Fixes: a95d70547c57 ("eal: factorize lcore main loop")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 lib/eal/common/eal_common_launch.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Patch

diff --git a/lib/eal/common/eal_common_launch.c b/lib/eal/common/eal_common_launch.c
index 5320c3bd3c..a06c402edf 100644
--- a/lib/eal/common/eal_common_launch.c
+++ b/lib/eal/common/eal_common_launch.c
@@ -18,6 +18,9 @@ 
 int
 rte_eal_wait_lcore(unsigned worker_id)
 {
+	if (unlikely(worker_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
 	while (rte_atomic_load_explicit(&lcore_config[worker_id].state,
 			rte_memory_order_acquire) != WAIT)
 		rte_pause();
@@ -35,6 +38,9 @@  rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int worker_id)
 {
 	int rc = -EBUSY;
 
+	if (unlikely(worker_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
 	/* Check if the worker is in 'WAIT' state. Use acquire order
 	 * since 'state' variable is used as the guard variable.
 	 */
@@ -93,6 +99,9 @@  rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
 enum rte_lcore_state_t
 rte_eal_get_lcore_state(unsigned lcore_id)
 {
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
 	return lcore_config[lcore_id].state;
 }