Project

General

Profile

Actions

Security #9060

closed
VJ VJ

lua: cached packet/flow/file/signature handles are non-owning and never invalidated -> UAF across calls

Security #9060: lua: cached packet/flow/file/signature handles are non-owning and never invalidated -> UAF across calls

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

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

8a40b054e13c93629de1ee9bb2294f53bedc7953
acf6ef1c75b443a42d975646da9c42c7cd3c4a0d

Severity:
LOW
Disclosure Date:

Description

  • Status: present in main (9b7938aec); owners/free paths verified in code (not yet reproduced)
  • Class: use-after-free / cross-object data disclosure from cached non-owning userdata handles
  • Component: suricata.packet (src/util-lua-packetlib.c), suricata.flow (src/util-lua-flowlib.c), suricata.file (src/util-lua-filelib.c), suricata.rule (src/util-lua-rule.c); same class as the dataset handle staleness after rule reload

Description

These libs wrap raw non-owning pointers in userdata: Packet* (packet.get()), Flow* (flow.get()), File* (file.get_file()), const Signature* (rule.get_rule(), from PacketAlert->s or the current signature). No handle carries a refcount, generation counter or invalidation hook; __gc only NULLs the wrapper (file/rule have no __gc) and is not called while the handle is still referenced.

A script that stores a handle in a global and uses it on a later call/tx/flow/event keeps a dangling pointer:

  • packet: Packet is returned to the pool after processing (tmqh-packetpool.c:168-215); PacketReinit frees ext_pkt and zeroes fields (packet.c:95-170); malloc-backed packets are SCFree@d (@decode.c:298-312) -> cross-packet data, torn payload/payload_len, UAF.
  • flow: FlowClearMemory -> FLOW_RECYCLE -> spare pool (flow-manager.c:1091-1104, :1141-1143); spare blocks are FlowFree@d when the pool is trimmed (@flow-spare-pool.c:217-240) -> UAF / cross-flow (tenant) data leak.
  • file: FileFree via FileContainerRecycle/FileContainerFree/FilesPrune (util-file.c:566, :495, :515, :1175) -> reads through freed name/magic/digest memory.
  • signature: SigFree on rule reload (detect-parse.c:2343, :2403) for output alert scripts (rule/luaxform states are recreated before the prune, output states are not, the same premise as the dataset handle staleness) -> UAF read in sid()/msg()/class_description().

Trigger pattern (per lib): cache the handle in log()/match() on the first event and dereference it on the second.

Fix direction

Chose one and document it:
  1. Call-scoped contract: document that handles are valid only during the callback that produced them; additionally stop exposing raw pointers where a value copy is enough (packet/flow fields are small).
  2. Generation/validity token: keep a per-state generation counter bumped on context change and have each handle store the generation at get() time; methods reject stale handles.
  3. Keep handles but add an engine-side invalidation hook (hard: the script may hold the only reference).

Tests

lua-packet-stale-handle, lua-flow-stale-handle, lua-file-stale-handle, lua-rule-stale-signature (all under ASAN; multi-event pcaps + rule reload for the signature case).


Subtasks 1 (0 open — 1 closed)

Security #9310: lua: cached packet/flow/file/signature handles are non-owning and never invalidated -> UAF across calls (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom