Project

General

Profile

Actions

Bug #9058

closed
VJ VJ

lua/bytevar: map() accepts any lightuserdata as Signature pointer (hardening)

Bug #9058: lua/bytevar: map() accepts any lightuserdata as Signature pointer (hardening)

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); hardening (not reachable today)
  • Class: unchecked pointer from a script argument
  • Component: src/util-lua-bytevarlib.c:41-45 (LuaBytevarMap)

Description

bytevar.map() validates only that the first argument is a lightuserdata and then treats it as a const Signature *:

if (!lua_islightuserdata(L, -2)) {
    return luaL_error(L, "bytevar.map: first argument must be the signature passed to init");
}
const Signature *s = lua_touserdata(L, -2);
...
DetectByteRetrieveSMVar(name, s, -1, &idx);

DetectByteRetrieveSMVar walks s->init_data, so a forged lightuserdata would be an arbitrary-pointer dereference. Today the only lightuserdata a script can obtain is the Signature * passed to init(), so this is not reachable; it should still fail closed.

Fix direction

Capture the expected Signature * at init()/thread-init time (registry) and require exact pointer equality; error otherwise. Optionally stop exposing the signature as a lightuserdata and pass an opaque handle.

Test

lua-bytevar-map-sig-arg: map(nil, "x") / map(<other lightuserdata>, "x") / extra args → clean Lua error, no deref.


Subtasks 1 (0 open — 1 closed)

Bug #9308: lua/bytevar: map() accepts any lightuserdata as Signature pointer (hardening) (8.0.x backport)ClosedVictor JulienActions

VJ Updated by Victor Julien about 2 months ago Actions #1

  • Status changed from New to In Progress
  • Assignee changed from OISF Dev to Victor Julien

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

  • Status changed from In Progress to In Review

MR1382

JI Updated by Jason Ish 27 days ago Actions #3

  • Subtask #9308 added

JI Updated by Jason Ish 27 days ago Actions #4

  • Severity set to LOW

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