Bug #9062
closedlua: LuaStateNeedProto returns 2 (no flow) treated as protocol match; ja3 type confusion
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: boolean/return-value confusion -> protocol check bypass and type confusion
- Component:
src/util-lua-common.c:102-110(LuaStateNeedProto) and its callers
Description¶
LuaStateNeedProto() returns LuaCallbackError(...) - which is 2 - when there is no flow:
Flow *flow = LuaStateGetFlow(luastate);
if (flow == NULL)
return LuaCallbackError(luastate, "internal error: no flow");
...
return (alproto == flow_alproto);
Most callers treat the result as a boolean and invert it (dns:40, ntp:32, ssh:41, smtp:46, http:39, tls:66/219/232, dnp3:160: if (!LuaStateNeedProto(...)) return error;), so the "no flow" value 2 is truthy and the check passes - the library proceeds as if the protocol matched and keeps the pushed error values on the stack. ja3:43-45 uses truthiness directly and selects ALPROTO_TLS.
Combined with a stale TX (separate issue), ja3.get_tx() wraps a non-TLS tx pointer as struct LuaTx {void *tx; AppProto} with alproto = ALPROTO_TLS, and the method casts it to SSLState* -> type confusion/UAF read.
Impact: low in normal configurations (no-flow with a stale tx is uncommon), but the contract is wrong and the ja3 path is a concrete type-confusion risk. No memory-safety issue on its own.
Fix direction¶
Return plain 0/false when there is no flow (and/or have callers compare == 1), and keep error reporting separate via LuaCallbackError.
Test¶
lua-txlibs-no-flow: call each protocol lib's get_tx() in a state without a flow; assert a clean Lua error, not a protocol match or a wrapped pointer.