Project

General

Profile

Actions

Bug #9064

closed
VJ VJ

lua: registry is script-writable in unsandboxed states -> pointer retyping/type confusion

Bug #9064: lua: registry is script-writable in unsandboxed states -> pointer retyping/type confusion

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

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

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 all LuaStateGet* 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.


Subtasks 1 (0 open — 1 closed)

Bug #9314: lua: registry is script-writable in unsandboxed states -> pointer retyping/type confusion (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom