Bug #9064
closedlua: registry is script-writable in unsandboxed states -> pointer retyping/type confusion
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: engine state tampering via the Lua registry in unsandboxed states -> type confusion
- Component:
src/util-lua.c:73-97(registry keys) and allLuaStateGet*consumers
Description¶
The registry holds non-owning engine pointers under plain lightuserdata keys (tv, packet, flow, tx, tx\_id, signature, packet alert, file, det\_ctx, direction, streaming buffer). In states where debug is available - output scripts (by design) and rule/transform scripts with security.lua.allow-restricted-functions: true - debug.getregistry() exposes the whole registry table. A script can move/copy pointer values between keys (for example put a packet pointer under the tx key or a Signature* under the PacketAlert key); the libs then type-cast the value with no identity check (dns/tls/http.get_tx(), rule.get_rule() reading pa->s), producing a correctly-typed but wrong-struct userdata -> type confusion/UAF.
This is distinct from metatable forgery: an immutable userdata type tag does not help when the pointer is injected through the registry.
Output scripts are trusted by design, so this does not cross a privilege boundary; it fails the "a script bug must not corrupt the engine" goal and would matter if the sandbox boundary ever moves.
Fix direction¶
Stop storing loose pointers in the registry: keep one typed per-state context struct (light userdata) with typed fields, or wrap each registry value in a tagged userdata/tag checked on read. At minimum document registry tampering as out of contract.
Test¶
lua-output-registry-tamper: output script uses debug.getregistry() to swap a packet pointer into the tx key and calls http/tls.get_tx() under ASAN; must fail cleanly.
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