Skip to content

tetragon: Add missing setup for matchParentBinaries selector#4888

Draft
olsajiri wants to merge 6 commits into
mainfrom
pr/olsajiri/match
Draft

tetragon: Add missing setup for matchParentBinaries selector#4888
olsajiri wants to merge 6 commits into
mainfrom
pr/olsajiri/match

Conversation

@olsajiri
Copy link
Copy Markdown
Contributor

@olsajiri olsajiri commented Apr 20, 2026

Tracing sensors (kprobe, lsm, uprobe, usdt, tracepoint) include
pfilter.h which references the PARENTS_MAP_ENABLED rodata constant to
gate parent-binary selector matching in BPF. The constant was only set
for the execve program in pkg/sensors/base/base.go, leaving it at zero
in all tracing sensors even when --parents-map-enabled is set.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 20, 2026

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit d304ae9
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69e8d56aa51c370008518dbd
😎 Deploy Preview https://deploy-preview-4888--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Apr 20, 2026
@olsajiri olsajiri force-pushed the pr/olsajiri/match branch 7 times, most recently from 0859862 to d304ae9 Compare April 22, 2026 14:04
@olsajiri olsajiri changed the title Pr/olsajiri/match tetragon: Add missing setup for matchParentBinaries selector Apr 22, 2026
@olsajiri olsajiri force-pushed the pr/olsajiri/match branch 4 times, most recently from a630c2d to 6950d68 Compare April 23, 2026 07:33
Tracing sensors (kprobe, lsm, uprobe, usdt, tracepoint) include
pfilter.h which references the PARENTS_MAP_ENABLED rodata constant to
gate parent-binary selector matching in BPF. The constant was only set
for the execve program in pkg/sensors/base/base.go, leaving it at zero
in all tracing sensors even when --parents-map-enabled is set.

Add setParentsMap() helper in generic.go that both appends the
ParentBinariesMap to the sensor's map list and rewrites
PARENTS_MAP_ENABLED=1 in every program's rodata.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Add TestMatchParentBinariesSetParentsMap to verify that sensor
construction correctly sets PARENTS_MAP_ENABLED in RewriteConstants and
includes ParentBinariesMap in the sensor maps when ParentsMapEnabled is
enabled, and does neither when it is disabled.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Add WithSetup() on the Builder that registers a function to run before
the observer is loaded. The returned cleanup function, if non-nil, is
called after the test completes.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Truncate the export file before each scenario (after the first) so each
scenario's event checker sees a clean stream without leftover events from
previous scenarios.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Currently the observer is created with WithMyPid() option, which means
all events must originate in observer's family (which means observer
itself or its kids).

This filter does not work reliably when we have multiple descendants,
and events comes from deepest kid first, which is case for test coming
in following changes.

The WithAllEvents hook creates observer without WithMyPid() option.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Add TestMatchParentBinariesKprobePolicytest that loads a kprobe policy
with matchParentBinaries selector and verifies the BPF filter in two
scenarios:
- lseek-pipe run via bash parent: events arrive (selector matches)
- lseek-pipe run via sh parent: no events arrive (selector filters out)

The test uses WithAllEvents hook, because I saw observer with WithMyPid()
option failing on it. The debug showed that the pidset filter won't work
properly when the deepest kid generated the event first.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
@olsajiri olsajiri force-pushed the pr/olsajiri/match branch from 6950d68 to 5ac7893 Compare April 23, 2026 10:21
@kobrineli
Copy link
Copy Markdown
Contributor

Oh, didnt notice that.. thanks!
But how did it work at all then?
I've tested it locally, and tests for parent binaries also passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants