From 7b55015e1487a5f407a760cfb4d9dbf1ddacd0cc Mon Sep 17 00:00:00 2001 From: David Marchand Date: Thu, 17 Jan 2019 14:12:57 +0100 Subject: [PATCH] eal: fix out of bound access when no CPU available In the unlikely case when the dpdk application is started with no cpu available in the [0, RTE_MAX_LCORE - 1] range, the master_lcore is automatically chosen as RTE_MAX_LCORE which triggers an out of bound access. Either you have a crash then, or the initialisation fails later when trying to pin the master thread on it. In my test, with RTE_MAX_LCORE == 2: $ taskset -c 2 ./master/app/testpmd --no-huge -m 512 --log-level *:debug [...] EAL: pthread_setaffinity_np failed PANIC in eal_thread_init_master(): cannot set affinity 7: [./master/app/testpmd() [0x47f629]] Bugzilla ID: 19 Fixes: 2eba8d21f3c9 ("eal: restrict cores auto detection") Cc: stable@dpdk.org Signed-off-by: David Marchand --- lib/librte_eal/common/eal_common_options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 4681333ede..80d790292e 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1388,6 +1388,8 @@ eal_adjust_config(struct internal_config *internal_cfg) /* default master lcore is the first one */ if (!master_lcore_parsed) { cfg->master_lcore = rte_get_next_lcore(-1, 0, 0); + if (cfg->master_lcore >= RTE_MAX_LCORE) + return -1; lcore_config[cfg->master_lcore].core_role = ROLE_RTE; } -- 2.20.1