Skip to content
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

pkg/sensors: fix binprm matchArgs test #2624

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bpf/process/types/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,9 @@ selector_arg_offset(__u8 *f, struct msg_generic_kprobe *e, __u32 selidx,
args += 4;
case file_ty:
case path_ty:
#ifdef __LARGE_BPF_PROG
case linux_binprm_type:
#endif
pass &= filter_file_buf(filter, (struct string_buf *)args);
break;
case string_type:
Expand Down
26 changes: 19 additions & 7 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6028,7 +6028,7 @@ func TestLinuxBinprmExtractPath(t *testing.T) {
{
MatchArgs: []v1alpha1.ArgSelector{
{
Operator: "In",
Operator: "Equal",
Index: 0,
Values: []string{"/usr/bin/id"},
},
Expand All @@ -6043,24 +6043,36 @@ func TestLinuxBinprmExtractPath(t *testing.T) {
err := sm.Manager.AddTracingPolicy(ctx, &bprmTracingPolicy)
assert.NoError(t, err)

command := exec.Command("/usr/bin/id")
targetCommand := exec.Command("/usr/bin/id")
filteredCommand := exec.Command("/usr/bin/uname")

ops := func() {
err = command.Start()
err = targetCommand.Start()
assert.NoError(t, err)
err = filteredCommand.Start()
assert.NoError(t, err)
defer command.Process.Kill()
defer targetCommand.Process.Kill()
defer filteredCommand.Process.Kill()
}

events := perfring.RunTestEvents(t, ctx, ops)

wantedEventExist := false
for _, ev := range events {
if kprobe, ok := ev.(*tracing.MsgGenericKprobeUnix); ok {
if int(kprobe.Msg.ProcessKey.Pid) == command.Process.Pid && kprobe.FuncName == "security_bprm_check" {
return
if int(kprobe.Msg.ProcessKey.Pid) == targetCommand.Process.Pid {
wantedEventExist = true
continue
}
if int(kprobe.Msg.ProcessKey.Pid) == filteredCommand.Process.Pid {
t.Error("kprobe event triggered by /usr/bin/uname should be filtered by the matchArgs selector")
break
}
}
}
t.Error("bprm error")
if !wantedEventExist {
t.Error("kprobe event triggered by /usr/bin/id should be present, unfiltered by the matchArgs selector")
}
}

// Test module loading/unloading on Ubuntu
Expand Down
Loading