Repository navigation
[9.6](backport #54645) auditbeat/module/auditd: fix kernel lost monitor client handling - #54730
Merged
Merged
Conversation
) When the auditd module uses a unicast socket, a goroutine polls the kernel's lost event counter using its own audit client. Two problems affected that client. The deferred cleanup was meant to close the monitor client, as its comment says, but called ms.client.Close(). That is the data client, which Run already closes, so the monitor's netlink socket was never closed. With the real Run and mock data and control clients, the process had one more open socket after Run returned than before it was called. The leak grows only when the module is stopped and started again in the same process. If creating the monitor client failed, the error was reported but the goroutine was started anyway with a nil client. Its first poll, 15 seconds later, called GetStatus on a nil *AuditClient and panicked. Nothing recovers panics in that goroutine, so the process exited. This was reproduced by using up the process's file descriptors so that the socket could not be opened. Move the goroutine body into monitorKernelLost, which returns without starting to poll if it has no client and closes the client it holds when it returns, including a replacement made after a failed poll. If a client cannot be created, the error is reported once and the kernel lost metric is no longer updated for the rest of the run. The client constructor and the poll interval are parameters of monitorKernelLost so that tests can make creation fail and polls fail quickly. Each of the four tests fails if the corresponding fix is reverted. The errors from creating the client now say what the client was for, and the log line for a failed status request no longer runs the message and the error together. (cherry picked from commit 1ebe6fc)
Contributor
🤖 GitHub commentsJust comment with:
|
|
Pinging @elastic/security-service-integrations (Team:Security-Service Integrations) |
Contributor
Author
|
This pull request is merged. |
efd6
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed commit message
When the auditd module uses a unicast socket, a goroutine polls the
kernel's lost event counter using its own audit client. Two problems
affected that client.
The deferred cleanup was meant to close the monitor client, as its
comment says, but called ms.client.Close(). That is the data client,
which Run already closes, so the monitor's netlink socket was never
closed. With the real Run and mock data and control clients, the
process had one more open socket after Run returned than before it was
called. The leak grows only when the module is stopped and started again
in the same process.
If creating the monitor client failed, the error was reported but the
goroutine was started anyway with a nil client. Its first poll, 15
seconds later, called GetStatus on a nil *AuditClient and panicked.
Nothing recovers panics in that goroutine, so the process exited. This
was reproduced by using up the process's file descriptors so that the
socket could not be opened.
Move the goroutine body into monitorKernelLost, which returns without
starting to poll if it has no client and closes the client it holds
when it returns, including a replacement made after a failed poll. If a
client cannot be created, the error is reported once and the kernel lost
metric is no longer updated for the rest of the run.
The client constructor and the poll interval are parameters of
monitorKernelLost so that tests can make creation fail and polls fail
quickly. Each of the four tests fails if the corresponding fix is
reverted. The errors from creating the client now say what the client
was for, and the log line for a failed status request no longer runs the
message and the error together.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesstresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
None. The only behaviour change is when the monitor client cannot be created: Auditbeat used to crash 15 seconds later, and now it reports the error and stops updating the
auditd.kernel_lostmetric for the rest of the run. There is no retry.How to test this PR locally
Each of the four tests fails if its fix is reverted. To see the original failures, run the real
Runwith the data and control clients mocked (asTestImmutabledoes) and count socket file descriptors before and afterRunreturns; or lowerRLIMIT_NOFILEand fill the remaining descriptors before callingRun, which makes the monitor goroutine panic after 15 seconds.Related issues
Known limitations
Rundoes not wait for the monitor goroutine, so it can briefly outliveRun. This was already the case.Newleaks the control client if creating the data client fails. That is a separate leak, tracked in auditbeat/auditd: New leaks the control client when creating the data client fails #54644./v7to/v9) will need the imports in the new test file updated, depending on which merges first.This is an automatic backport of pull request #54645 done by [Mergify](https://mergify.com).