Project

General

Profile

Actions

Security #9057

closed
VJ VJ

lua/bytevar: value() reads a stale or uninitialized byte_values slot

Security #9057: lua/bytevar: value() reads a stale or uninitialized byte_values slot

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

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

3f8ff7ceab004f2713708834b5bbba3b1d8ebe20

Severity:
LOW
Disclosure Date:

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):

lua_pushinteger(L, det_ctx->byte_values[*bytevar_id]);

Two engine-side properties make this unsafe for direct reads:

  1. det_ctx->byte_values is allocated with SCMalloc and never zeroed (src/detect-engine.c:3554-3556), so a slot that has not been written this thread contains uninitialized heap data.
  2. The array is indexed by the signature's per-rule local_id, and bytevar.map() resolves variables with sm_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 by cd4e728b7 does not apply to the Lua lib). If that extractor did not run for the current packet, the slot holds another signature's value (same local_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 (SCCalloc or memset) at thread-ctx init.
  • Add a bounds/version check in value() (compare against det_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.


Subtasks 1 (0 open — 1 closed)

Security #9307: lua/bytevar: value() reads a stale or uninitialized byte_values slot (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom