From 5de98ef86c6dd9e14a55f1c449ea9f61624cfb3f Mon Sep 17 00:00:00 2001 From: yidong0635 Date: Thu, 4 Aug 2022 13:33:28 +0800 Subject: [PATCH] reactor: Check error return for spdk_thread_lib_init_ext. DPDK may use this NULL pointer to access its member, And then got segmentation fault. But we only need it exit or report normal error. To minimize the impact, and to prevent these going on, we add check the error return for creating NULL mempool in spdk_thread_lib_init_ext in spdk_reactors_init. when error returning from spdk_thread_lib_init_ext in spdk_reactors_init. It contains thread_lib_init which reports error for failed mempool. Thus, codes will return and will not cause segmentation fault. Fixes issue #2620. Signed-off-by: yidong0635 Change-Id: I63369fdaeb231196e8f8daa826eb5b057ed829b8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13842 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Michal Berger --- lib/event/reactor.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 79bba543d..65f3d0e4f 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -246,8 +246,15 @@ spdk_reactors_init(size_t msg_mempool_size) memset(g_reactors, 0, (g_reactor_count) * sizeof(struct spdk_reactor)); - spdk_thread_lib_init_ext(reactor_thread_op, reactor_thread_op_supported, - sizeof(struct spdk_lw_thread), msg_mempool_size); + rc = spdk_thread_lib_init_ext(reactor_thread_op, reactor_thread_op_supported, + sizeof(struct spdk_lw_thread), msg_mempool_size); + if (rc != 0) { + SPDK_ERRLOG("Initialize spdk thread lib failed\n"); + spdk_mempool_free(g_spdk_event_mempool); + free(g_reactors); + free(g_core_infos); + return rc; + } SPDK_ENV_FOREACH_CORE(i) { reactor_construct(&g_reactors[i], i);