Project

General

Profile

Actions

Security #9050

closed
VJ VJ

lua: flowint/flowvar register and bytevar map NULL-deref when DetectLuaData is unset (output/transform scripts)

Security #9050: lua: flowint/flowvar register and bytevar map NULL-deref when DetectLuaData is unset (output/transform scripts)

Added by Victor Julien 2 months ago. Updated 7 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Label:
CVE:
Git IDs:

4086dc23f03c247a2780d6c9cf8b6406675aa824

Severity:
LOW
Disclosure Date:

Description

  • Status: present in main (9b7938aec); confirmed with ASAN
  • Class: NULL pointer dereference (engine crash) from output/transform Lua scripts
  • Component: src/util-lua-flowintlib.c, src/util-lua-flowvarlib.c, src/util-lua-bytevarlib.c

Description

LuaFlowintRegister() (src/util-lua-flowintlib.c:52), LuaFlowvarRegister() (src/util-lua-flowvarlib.c:52) and LuaBytevarMap() (src/util-lua-bytevarlib.c:46) call GetLuaData() and dereference the result without a NULL check:

DetectLuaData *ld = GetLuaData(L);
if (ld->flowints >= DETECT_LUA_MAX_FLOWINTS) { ... }   /* flowintlib.c:59 */

GetLuaData() reads the luaext_key_ld registry entry, which is only set by the rule keyword path (LuaStateSetDetectLuaData(), src/detect-lua.c:425). The lua output module creates its state with LuaGetState() = luaL_newstate() + luaL_openlibs() (src/output-lua.c:452-454, 587-589) and never sets the key; src/detect-transform-luaxform.c also never sets it. The builtins are loaded in both cases (SCLuaRequirefBuiltIns), so a script can require("suricata.flowint") and call register().

LuaBytevarGet() checks ld for NULL (util-lua-bytevarlib.c:77) - the register/map paths were simply missed.

ASAN evidence (main \@ 9b7938aec)

Output script init() calling require("suricata.flowint").register("x"):

==...==ERROR: AddressSanitizer: SEGV on unknown address ... (pc ... bp ... sp ...)
    #0 LuaFlowintRegister   src/util-lua-flowintlib.c:59
    ...
    #7 LuaScriptInit        src/output-lua.c:479
    #8 OutputLuaLogInit     src/output-lua.c:761

grep LuaStateSetDetectLuaData = 0 occurrences in src/output-lua.c and src/detect-transform-luaxform.c, so luaxform scripts reach the same crash.

Fix direction

NULL-check in all three entry points and raise a Lua error (matching LuaBytevarGet):

DetectLuaData *ld = GetLuaData(L);
if (ld == NULL)
    return luaL_error(L, "flowvar/flowint/bytevar API not available in this context");

Alternatively document and enforce that these APIs are rule-only. Regression tests: lua-bytevar-no-detdata (flowint/flowvar/bytevar calls from output and transform scripts) asserting a Lua error and no crash under ASAN.


Subtasks 1 (0 open — 1 closed)

Security #9300: lua: flowint/flowvar register and bytevar map NULL-deref when DetectLuaData is unset (output/transform scripts) (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom