Project

General

Profile

Actions

Security #9048

closed
VJ VJ

lua: log API allows out of bounds read

Security #9048: lua: log API allows out of bounds read

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

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

3bece75d5b97d60522a1057af7ac1dfb667d42b2

Severity:
LOW
Disclosure Date:

Description

```
SCLogMessageJSON() copies the rendered JSON into the caller's fixed-size stack buffer with

src/util-debug.c:247-248

SCJbClose(js);
memcpy(buffer, SCJbPtr(js), MIN));

SCJbLen() is js.buf.len() (rust/src/jsonbuilder.rs:1137) and does not include a NUL terminator. The destination buffer is char buffer[SC_LOG_MAX_LOG_MSG_LEN] = ""; (src/util-debug.c:655-656, SC_LOG_MAX_LOG_MSG_LEN = 8192 + PATH_MAX + 512 = 12800 on Linux). The aggregate initialization zeroes the whole array, so a render shorter than buffer_size is safe by accident; when SCJbLen(js) >= buffer_size the memcpy fills all 12800 bytes and nothing terminates the string.

Every engine-log sink then consumes it as a C string:

SCLogPrintToStream(): fprintf(fd, "%s\n", msg) (src/util-debug.c:168) — console and file outputs
SCLogPrintToSyslog(): syslog(level, "%s", msg) (src/util-debug.c:195)

so the %s scan walks past the end of the stack object until it finds a NUL byte: out-of-bounds stack read. How far it reads is stack-content dependent, so adjacent stack data (other locals, pointers) can end up in the log output, and the scan can crash if it reaches an unmapped page. Any log output configured with type: json (src/util-debug.c:1487-1495) is affected.

The other JSON consumers (fwrite(SCJbPtr(js), SCJbLen(js), ...)) are length-based and safe; this memcpy is the only place that combines a length-bounded copy with a C-string consumer.

Trigger

Any engine log message long enough to be clamped by the SCLog* formatter is sufficient: the macros do vsnprintf(msg, sizeof(msg), fmt, ap) into a 12800-byte buffer (src/util-debug.c:737-745), so a longer message becomes 12799 chars, and the ~145 bytes of JSON framing (timestamp, keys, quotes, thread name) then push SCJbLen past buffer_size. JSON escaping of quotes/backslashes can push shorter messages over the limit as well.

Reachable from Lua through the engine-log API (suricata.log, src/util-lua-log.c), which passes arbitrarily long strings. No default rule/decoder path is known to produce a ~12.8 KB log message, so the issue is latent with respect to traffic alone, but it is deterministic as soon as one such message is logged (Lua script, plugin, or a future call site).
```

I think this found by my local analysis, but it's possible I forgot about someone reporting it.


Subtasks 1 (0 open — 1 closed)

Security #9298: lua: log API allows out of bounds read (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 26 days ago Actions #3

  • Subtask #9298 added

JI Updated by Jason Ish 26 days ago Actions #4

  • Severity set to LOW

JI Updated by Jason Ish 26 days ago Actions #5

  • GHSA set to GHSA-9cwj-pq39-fhj9

JI Updated by Jason Ish 25 days ago Actions #6

  • Git IDs updated (diff)

JI Updated by Jason Ish 25 days ago Actions #7

  • Status changed from In Review to Closed

JI Updated by Jason Ish 7 days ago Actions #8

  • Private changed from Yes to No
Actions

Also available in: PDF Atom