Project

General

Profile

Actions

Bug #9071

closed
VJ VJ

lua: memory_limit_error is never cleared -> later errors misreported as memory-limit

Bug #9071: lua: memory_limit_error is never cleared -> later errors misreported as memory-limit

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: error misclassification / stats corruption (diagnostics only, no memory safety)
  • Component: src/util-lua-sandbox.c, src/detect-lua.c

Description

memory_limit_error is set by the sandbox allocator (src/util-lua-sandbox.c:70 for new allocations, :86 for reallocations) and is never cleared:

  • SCLuaSbResetInstructionCounter() clears blocked_function_error and instruction_count_error (util-lua-sandbox.c:426-427) but not memory_limit_error;
  • no other site resets it.

DetectLuaRunMatch() classifies an error by checking the flags in order (detect-lua.c:180-190):

if (context->blocked_function_error) { ... }
else if (context->instruction_count_error) { ... }
else if (context->memory_limit_error) {
    StatsCounterIncr(..., det_ctx->lua_memory_limit_errors);
    reason = "memory limit exceeded";
    ...
}

Once a script has hit the memory limit even once, every subsequent error in that state - blocked function, script bug, real memory-limit - is reported as "memory limit exceeded", counted in detect.lua.memory_limit_errors, and the real Lua error text is discarded. Diagnostics for long-lived states are therefore wrong after the first such event.

Fix direction

Clear memory_limit_error in the per-call reset (SCLuaSbResetInstructionCounter) after classification has consumed it, i.e. treat the three flags consistently:

sb->blocked_function_error = false;
sb->instruction_count_error = false;
sb->memory_limit_error = false;

Regression test

lua-memory-error-sticky: trigger a memory-limit error once, then induce an unrelated script error; assert the second error is reported/counted as a generic script error, not a memory-limit error.


Subtasks 1 (0 open — 1 closed)

Bug #9321: lua: memory_limit_error is never cleared -> later errors misreported as memory-limit (8.0.x backport)ClosedVictor JulienActions

PA Updated by Philippe Antoine about 2 months ago Actions #1

  • Status changed from New to Triaged
  • Assignee set to OISF Dev
  • Severity set to LOW

I would classify it as a BUG, not security

JI Updated by Jason Ish about 1 month ago Actions #2

  • Status changed from Triaged to In Review

MR1382

JI Updated by Jason Ish about 1 month ago Actions #3

  • Assignee changed from OISF Dev to Victor Julien

JI Updated by Jason Ish 27 days ago Actions #4

  • Subtask #9321 added

JI Updated by Jason Ish 27 days ago Actions #5

  • Tracker changed from Security to Bug
  • Severity deleted (LOW)

JI Updated by Jason Ish 26 days ago Actions #6

  • Status changed from In Review to Closed

JI Updated by Jason Ish 8 days ago Actions #7

  • Private changed from Yes to No
Actions

Also available in: PDF Atom