Security #9057
closedlua/bytevar: value() reads a stale or uninitialized byte_values slot
3f8ff7ceab004f2713708834b5bbba3b1d8ebe20
Description
- Status: present in
main(9b7938aec); mechanism code-confirmed, repro not yet executed - Class: stale/uninitialized memory read exposed to Lua
- Component:
src/util-lua-bytevarlib.c(LuaBytevarValue),src/detect-engine.c(byte\_values allocation)
Description¶
LuaBytevarValue() reads the per-thread byte_values array with no bound or validity check (src/util-lua-bytevarlib.c:102):
Two engine-side properties make this unsafe for direct reads:
det_ctx->byte_valuesis allocated withSCMallocand never zeroed (src/detect-engine.c:3554-3556), so a slot that has not been written this thread contains uninitialized heap data.- The array is indexed by the signature's per-rule
local_id, andbytevar.map()resolves variables withsm_list = -1(util-lua-bytevarlib.c:61→src/detect-byte.c:42), i.e. it can map an extraction registered for a different match list (the same-list restriction added bycd4e728b7does not apply to the Lua lib). If that extractor did not run for the current packet, the slot holds another signature's value (samelocal_id) or uninitialized data from a previous packet/thread.
Trigger sketch: a rule with http.uri; byte_extract:4,0,uv,string; packet; content:"GET"; lua:mix.lua; where the Lua keyword runs on a packet for which the extraction list was not evaluated; bv = bytevar.get("uv"); bv:value() then reads a stale/uninitialized slot.
The index itself cannot exceed the array (ids are engine-generated uint8_t local ids, and the array is sized from the same de\_ctx's byte_extract_max_local_id + 1); this is a data-validity bug, not an OOB.
Fix direction¶
- Zero-initialize
byte_values(SCCallocormemset) at thread-ctx init. - Add a bounds/version check in
value()(compare againstdet_ctx->de_ctx->byte_extract_max_local_id) as fail-closed defense. - Consider tracking a per-slot "set this packet/transaction" marker and returning nil until the extractor ran.
Tests¶
lua-bytevar-stale (two rules whose local ids collide, one extractor not run for the packet; the script must not observe the other rule's value), lua-bytevar-id-bound (defensive bound), and a first-use case that must yield 0/nil rather than uninitialized data.
VJ Updated by Victor Julien about 2 months ago
- Status changed from New to In Progress
- Assignee changed from OISF Dev to Victor Julien
JI Updated by Jason Ish about 1 month ago
- Status changed from In Progress to In Review
MR1382