From 20c73f9e8b2eac32b4d7925c837ae5af994306b3 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 13 Feb 2024 09:51:15 +0100 Subject: [PATCH] multi-tenant: fix coverity warning Rework locking logic to avoid the following coverity warning. ** CID 1591966: Concurrent data access violations (MISSING_LOCK) /src/detect-engine-loader.c: 475 in DetectLoadersSync() 474 SCCtrlMutexLock(loader->tv->ctrl_mutex); >>> CID 1591966: Concurrent data access violations (MISSING_LOCK) >>> Accessing "loader->tv" without holding lock "DetectLoaderControl_.m". Elsewhere, "DetectLoaderControl_.tv" is written to with "DetectLoaderControl_.m" held 1 out of 1 times (1 of these accesses strongly imply that it is necessary). 475 pthread_cond_broadcast(loader->tv->ctrl_cond); 476 SCCtrlMutexUnlock(loader->tv->ctrl_mutex); The warning is harmless. --- src/detect-engine-loader.c | 2 +- src/detect-engine-loader.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/detect-engine-loader.c b/src/detect-engine-loader.c index 9073c1e9c29d..153c056a85b4 100644 --- a/src/detect-engine-loader.c +++ b/src/detect-engine-loader.c @@ -578,8 +578,8 @@ static TmEcode DetectLoaderThreadInit(ThreadVars *t, const void *initdata, void DetectLoaderControl *loader = &loaders[ftd->instance]; SCMutexLock(&loader->m); - loader->tv = t; SCMutexUnlock(&loader->m); + loader->tv = t; return TM_ECODE_OK; } diff --git a/src/detect-engine-loader.h b/src/detect-engine-loader.h index 8a6f7b8f17be..7224279b960b 100644 --- a/src/detect-engine-loader.h +++ b/src/detect-engine-loader.h @@ -44,9 +44,9 @@ typedef struct DetectLoaderTask_ { typedef struct DetectLoaderControl_ { int id; int result; /* 0 for ok, error otherwise */ - ThreadVars *tv; /* loader threads threadvars - for waking them up */ - SCMutex m; + SCMutex m; /**< mutex protectx result and task_list */ TAILQ_HEAD(, DetectLoaderTask_) task_list; + ThreadVars *tv; /* loader threads threadvars - for waking them up */ } DetectLoaderControl; int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx, LoaderFreeFunc FreeFunc);