From 46a53aee73a22d902ec2875d044d520c12144c1b Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Thu, 21 Aug 2025 09:57:27 -0400 Subject: [PATCH] engine/mt: Ensure master lock held for reload Issue: 7819 DetectEngineReload must hold the `master->lock`; recent changes changed the locking usages to avoid deadlock when registering/handling tenants. These changes added the presumption that the master lock is held at a higher level. Coverity highlighted that the lock is not held consistently. --- src/detect-engine.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/detect-engine.c b/src/detect-engine.c index 543e140c19..f77452873a 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -2303,6 +2303,7 @@ static void InjectPackets( * * If called in unix socket mode, it's possible that we don't have * detect threads yet. + * NOTE: master MUST be locked before calling this * * \retval -1 error * \retval 0 no detection threads @@ -4859,8 +4860,13 @@ int DetectEngineReload(const SCInstance *suri) DetectEngineDeReference(&old_de_ctx); SCLogDebug("going to reload the threads to use new_de_ctx %p", new_de_ctx); + + DetectEngineMasterCtx *master = &g_master_de_ctx; + SCMutexLock(&master->lock); /* update the threads */ DetectEngineReloadThreads(new_de_ctx); + SCMutexUnlock(&master->lock); + SCLogDebug("threads now run new_de_ctx %p", new_de_ctx); /* walk free list, freeing the old_de_ctx */