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
Actions

Also available in: PDF Atom