-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle leak of process info in hostfs
provider for add_session_metadata
#42398
base: main
Are you sure you want to change the base?
Conversation
Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform) |
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
// in this case, give us a few iterations for us to get the exec, since things can arrive out of order. | ||
if cand.removeAttempt < exitRemoveAttempts { | ||
cand.removeAttempt += 1 | ||
db.removalMap[pid] = cand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? I don't see it being removed prior to this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are iterating over db.removalMap
...
for pid, cand := range db.removalMap {
Seems like db.removalMap[pid] = cand
is adding something that is already in the map ...
Oh, we are updating cand.removeAttempt
, is that we it needs to be re-added? Why doesn't that update the thing in the map directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that updates the existing entry in the map. The compiler won't let you do map[key].struct_val = new
, if that's what you're thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that line 75 changes what's in the map.
You mean the auditd events come out of order? |
@haesbaert so, I'm not sure how the ordering happens; my current theory is that because there's so many channels, threads and mutexes between the netlink sockets and this processor, that things will invariably end up out of order, even if we get them in-order from netlink. |
Alright, We're gonna have to hold off on this for a bit, I just discovered that auditbeat configures netlink by default to aggressively drop events: if ms.backpressureStrategy&(bsKernel|bsAuto) != 0 {
// "kernel" backpressure mitigation strategy
//
// configure the kernel to drop audit events immediately if the
// backlog queue is full.
if status.FeatureBitmap&libaudit.AuditFeatureBitmapBacklogWaitTime != 0 {
ms.log.Info("Setting kernel backlog wait time to prevent backpressure propagating to the kernel.")
if err = ms.client.SetBacklogWaitTime(0, libaudit.NoWait); err != nil {
return fmt.Errorf("failed to set audit backlog wait time in kernel: %w", err)
}
} else {
if ms.backpressureStrategy == bsAuto {
ms.log.Warn("setting backlog wait time is not supported in this kernel. Enabling workaround.")
ms.backpressureStrategy |= bsUserSpace
} else {
return errors.New("kernel backlog wait time not supported by kernel, but required by backpressure_strategy")
}
}
} which kind of throws the whole strategy of this out the window, since the processor has no way of knowing how complete our dataset is. Going back to the drawing board... |
Proposed commit message
Fixes #42317
So, it turns out that the processsDB used by the procfs provider in
add_session_metadata
expects events to come in order, which won't always be the case under load. If we get a an exit event before the exec event, we'll drop the exit event, and then the process event will remain in thedb.processes
map indefinitely. In addition to this, auditbeat is configured to tell netlink to drop events, meaning that under load, we can lose either the exec or the exit event, potentially leading to a leak if we can never pair up the two for a given process.This alters the DB so we don't drop orphaned exit events, and instead the DB reaper will wait a few iterations of
reapProcs()
to try to match the orphaned exit. We also optionally reap processexec
events. I've tested this under load, and it does prevent the process DB from growing indefinitely.There's a few caveats to this as-is:
db.removalMap
, which means we'll be using more memory until those exit events are reaped. I can't really think of a good way around this./proc
.There's also a few smaller changes to the process DB:
I'm still running performance tests on this, as the behavior is a bit bursty and hard to measure without some proper scripts. Will update when I have results.
How to test
Run auditbeat with the following:
Grep for the
REAPER:
log line to examine the following the state of the various DB maps.Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.