From c019eb4d678971d3115c29a702d39bd448ca1330 Mon Sep 17 00:00:00 2001 From: Sebastian Brzezinka Date: Wed, 18 Jan 2023 18:45:50 +0100 Subject: [PATCH] llvm_vfio_fuzz: handle thread create failure In case of `pthread_create` or `spdk_thread_create` failed stop spdk app with `-1` error code Signed-off-by: Sebastian Brzezinka Change-Id: Id5d0f6716917f42e06fbda7db9285deb320e309a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16338 Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris --- test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c b/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c index a60ed62a8..16486180f 100644 --- a/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c +++ b/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c @@ -142,7 +142,7 @@ io_terminate(void *ctx) static void exit_handler(void) { - if (g_io_thread.io_ctrlr_path) { + if (g_io_thread.io_ctrlr_path && g_io_thread.thread) { spdk_thread_send_msg(g_io_thread.thread, io_terminate, &g_io_thread); } else { @@ -392,6 +392,13 @@ init_io(void *ctx) } g_io_thread.thread = spdk_thread_create("io_thread", NULL); + if (g_io_thread.thread == NULL) { + fprintf(stderr, "cannot create io thread\n"); + spdk_app_stop(-1); + pthread_kill(g_fuzz_td, SIGSEGV); + return NULL; + } + spdk_thread_send_msg(g_io_thread.thread, start_io_poller, &g_io_thread); return NULL; @@ -400,15 +407,25 @@ init_io(void *ctx) static void begin_fuzz(void *ctx) { + int rc = 0; + g_reactor_td = pthread_self(); - pthread_create(&g_fuzz_td, NULL, start_fuzzer, NULL); + rc = pthread_create(&g_fuzz_td, NULL, start_fuzzer, NULL); + if (rc != 0) { + spdk_app_stop(-1); + return; + } /* posix thread is use to avoid deadlock during spdk_nvme_connect * vfio-user version negotiation may block when waiting for response */ if (g_io_thread.io_ctrlr_path) { - pthread_create(&g_io_thread.io_td, NULL, init_io, NULL); + rc = pthread_create(&g_io_thread.io_td, NULL, init_io, NULL); + if (rc != 0) { + spdk_app_stop(-1); + pthread_kill(g_fuzz_td, SIGSEGV); + } } }