Skip to content

cherry: procmon memory fix (#503, #507) - #508

Merged
h0x0er merged 3 commits into
mainfrom
cherry/procmon-memory-fix
Nov 2, 2026
Merged

h0x0er merged 3 commits into
mainfrom
cherry/procmon-memory-fix

Conversation

@venkata-stepsecurity

Copy link
Copy Markdown
Collaborator

Cherry-pick of the procmon memory fix from int to main: #503 and #507.

Commits (picked with -x):

#503 also reverted #501 on int. #501 was never on main, so that revert is not included. Before #501, these files were identical on main and int.

After this PR, procmon.go, procmon_linux.go, procmon_test.go, procmon_linux_test.go, go.mod and go.sum are identical to int (cce1d50). fileMonitorAuditRule is defined once.

Testing

Audit events were kept in ProcessMonitor.Events forever. send() on a
connected socket is audited as sendto without an address, so those
events never became ready and were never released, and the agent grew
by about 1.4 GiB per minute on a localhost-streaming workload
(harden-runner#709). Under the same load the netlink socket overflowed
(ENOBUFS), receive returned and audit monitoring stopped for the rest
of the job.

Use go-libaudit's Reassembler, which Auditbeat uses, with Auditbeat's
defaults: at most 50 events in flight, a 2 second timeout and
maintenance every 500 ms. Every event is delivered once, complete or
evicted, so nothing is kept after delivery. The first qualifying PATH
is kept, as before. Like Auditbeat, receive stops only when the client
is closed: other errors, including ENOBUFS, are counted and receiving
continues, and records with an invalid header are dropped. Sequence
gaps and records whose fields cannot be parsed are counted and logged
on powers of two.

Bump go-libaudit from v2.3.2 to v2.6.2: v2.3.2 panics in parseSockaddr
on a SOCKADDR record shorter than expected (elastic/go-libaudit#152),
which stops the agent.

This replaces the event map and idle sweep from #501, reverted in the
previous commit.

(cherry picked from commit 018a9e6)
go-libaudit v2.6.2 pins github.com/elastic/go-licenser in rule/tools.go
behind the tools build tag. It is not built into the agent, but go mod
vendor needs its checksum.

(cherry picked from commit 3ac31cc)
go-libaudit's reassembler delivers events in sequence order. Records
that are not part of an audited syscall, such as BPF program loads and
unloads or ANOM_PROMISCUOUS, can arrive alone without a record that
completes an event, so each one held every later event until it timed
out (up to 2 s, or until 50 events were in flight). Handlers that look
up the parent process in /proc can miss it once it has exited.

Pass a record to the reassembler only if it is a SYSCALL record or
belongs to an event whose SYSCALL record was passed. Every record the
agent uses follows the SYSCALL record. Records that arrive after their
event was delivered are dropped instead of starting a new event.

Pushing, maintenance and the final flush take the same lock, so an
event cannot be given up between a record being admitted and being
pushed.

(cherry picked from commit efd33da)
@h0x0er
h0x0er merged commit 373f516 into main Nov 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants