Skip to content

[9.6](backport #54645) auditbeat/module/auditd: fix kernel lost monitor client handling - #54730

Merged
efd6 merged 1 commit into
9.6from
mergify/bp/9.6/pr-54645
Nov 16, 2026
Merged

efd6 merged 1 commit into
9.6from
mergify/bp/9.6/pr-54645

Conversation

@mergify

@mergify mergify Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

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

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using 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_lost metric for the rest of the run. There is no retry.

How to test this PR locally

cd auditbeat
mage fields
cd module/auditd
go test -race -count=1 -run TestMonitorKernelLost .

Each of the four tests fails if its fix is reverted. To see the original failures, run the real Run with the data and control clients mocked (as TestImmutable does) and count socket file descriptors before and after Run returns; or lower RLIMIT_NOFILE and fill the remaining descriptors before calling Run, which makes the monitor goroutine panic after 15 seconds.

Related issues

Known limitations


This is an automatic backport of pull request #54645 done by [Mergify](https://mergify.com).

)

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)
@mergify
mergify Bot requested a review from a team as a code owner November 16, 2026 19:34
@mergify mergify Bot added the backport label Nov 16, 2026
@mergify mergify Bot assigned efd6 Nov 16, 2026
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 16, 2026
@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is merged.

@efd6
efd6 enabled auto-merge (squash) November 16, 2026 20:11
@efd6
efd6 merged commit e7cba3c into 9.6 Nov 16, 2026
93 of 95 checks passed
@efd6
efd6 deleted the mergify/bp/9.6/pr-54645 branch November 16, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant