Actions
Bug #9074
closed
VJ
VJ
lua: flowvar/flowint register() races shared DetectLuaData from thread_init; refcount leak on limit path
Bug #9074:
lua: flowvar/flowint register() races shared DetectLuaData from thread_init; refcount leak on limit path
Affected Versions:
Effort:
Difficulty:
Label:
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: data race on shared state + refcount leak on the error path
- Component:
src/util-lua-flowvarlib.c:51-66,src/util-lua-flowintlib.c:51-66,src/detect-lua.c:425/452-460
Description¶
DetectLuaData (ld) is created once per signature at parse time and shared by every per-thread Lua state (detect-lua.c:425 stores it in each state; thread_init() runs per worker at :452-460). register() mutates ld directly:
*flowvar_id = VarNameStoreRegister(name, VAR_TYPE_FLOW_VAR); /* before the limit check */
if (*flowvar_id == 0) return luaL_error(...);
if (ld->flowvars >= DETECT_LUA_MAX_FLOWVARS) return luaL_error(...);
ld->flowvar[ld->flowvars++] = *flowvar_id;
- Two worker threads running
thread_init()(ormatch()) concurrently perform an unsynchronized check-then-append on the same arrays. The 15-entry cap prevents an OOB, but the counter and entries can be duplicated or lost, so script registrations are nondeterministic. - The limit check runs after
VarNameStoreRegister, so the 16th registration increments the global name-store refcount but is never recorded inld;DetectLuaFree(detect-lua.c:805-809) only unregisters entries it knows about, so one refcount/name entry leaks per over-limit call.
No memory corruption (array is capped).
Fix direction¶
- Move
VarNameStoreRegisterafter the limit check and unregister on the error path. - Serialize
ldmutation (mutex) or, preferably, make registrationinit-only / buildldbefore threads start and rejectregister()fromthread_init/match.
Tests¶
lua-multithread-register (register in thread_init under --runmode workers, TSAN) and a 16-registration over-limit case asserting clean failure and no leaked name-store entry (engine restart/teardown).
Actions