From: Victor Julien Date: Tue, 13 Feb 2024 08:51:15 +0000 (+0100) Subject: multi-tenant: fix coverity warning X-Git-Tag: suricata-8.0.0-beta1~1751 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d7c3d8d5970c0629f2358ab91ed895328efa112;p=thirdparty%2Fsuricata.git 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 itself is harmless. --- diff --git a/src/detect-engine-loader.c b/src/detect-engine-loader.c index 9073c1e9c2..153c056a85 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 8a6f7b8f17..f43ff9a549 100644 --- a/src/detect-engine-loader.h +++ b/src/detect-engine-loader.h @@ -43,10 +43,14 @@ 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; - TAILQ_HEAD(, DetectLoaderTask_) task_list; + ThreadVars *tv; /**< loader threads threadvars - for waking them up */ + + /** struct to group members and mutex */ + struct { + SCMutex m; /**< mutex protects result and task_list */ + int result; /**< 0 for ok, error otherwise */ + TAILQ_HEAD(, DetectLoaderTask_) task_list; + }; } DetectLoaderControl; int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx, LoaderFreeFunc FreeFunc);