Project

General

Profile

Actions

Bug #9214

closed
JI VJ

lua: give each setup invocation a separate instruction budget

Bug #9214: lua: give each setup invocation a separate instruction budget

Added by Jason Ish about 1 month ago. Updated 8 days ago.

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

Description

Summary

During Lua rule setup, execution of the top-level script and init() shares one instruction budget. Worker initialization similarly shares a budget between the top-level script and thread_init(), for both Lua rules and Lua transforms.

Consequently, setup can fail when both stages individually fit within security.lua.max-instructions, but their combined instruction count exceeds it. Normal match() and transform() invocations already receive separate budgets.

The temporary rule-setup state and each worker state are distinct: init() and thread_init() do not themselves share one counter.

Intended behavior

Apply security.lua.max-instructions independently to each Lua invocation, including setup. Reset the counter before executing the script chunk, init(), and thread_init().

Each invocation must remain subject to the configured limit. An individually over-budget chunk or initializer must still fail; this change does not exempt rule loading or engine startup from instruction limits.

The previous documentation did not clearly define whether setup stages shared a budget. This ticket makes the intended per-invocation policy explicit and applies it consistently.

Validation

  • Use a chunk and initializer that each fit within the limit but exceed it together. Setup should succeed with separate budgets and fail under the previous cumulative accounting.
  • Include an initializer that individually exceeds the limit. Setup should fail, confirming the limit remains enforced.
  • Cover rule init(), rule thread_init(), and transform thread_init().

Implementation and review

Commit 4462e550712bb9435ea111813c71b0921e0723aa on lua-fixes/v3 implements the resets in src/detect-lua.c and src/detect-transform-luaxform.c.

The matching Suricata-Verify tests, tests/lua-sbx-instr-init and tests/lua-sbx-instr-threadinit, need strengthening. They use a limit of 500 instructions, negligible top-level work, and simple 50-iteration initializer loops; source inspection suggests they would also pass before the change. Substantial work is needed in both the chunk and the relevant initializer to exercise cumulative exhaustion.

The lifecycle, implementation, and tests were reviewed statically. No builds or tests were run during that review, and no production incident was established. Stable-branch impact has not been assessed.


Subtasks 1 (0 open — 1 closed)

Bug #9337: lua: give each setup invocation a separate instruction budget (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom