Skip to content

Commit 972301f

Browse files
FedeDPmtardy
authored andcommitted
new(pkg/sensors): add kprobe test around returnCopy.
The test uses `returnCopy` on index 1 element, without any prior index 0 element. This will help avoid future regressions like #4488. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
1 parent 97cc3ba commit 972301f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pkg/sensors/tracing/kprobe_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,48 @@ spec:
605605
runKprobeObjectRead(t, readHook, checker, fd, fd2)
606606
}
607607

608+
// Differently from other tests using returnCopy,
609+
// this one skips index 0 element to avoid future regressions
610+
// like https://github.com/cilium/tetragon/issues/4488.
611+
func TestKprobeObjectReturnCopy(t *testing.T) {
612+
fd, fd2, _ := createTestFile(t)
613+
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))
614+
readHook := `
615+
apiVersion: cilium.io/v1alpha1
616+
kind: TracingPolicy
617+
metadata:
618+
name: "sys-read"
619+
spec:
620+
kprobes:
621+
- call: "sys_read"
622+
syscall: true
623+
args:
624+
- index: 1
625+
type: "char_buf"
626+
returnCopy: true
627+
- index: 2
628+
type: "size_t"
629+
selectors:
630+
- matchPIDs:
631+
- operator: In
632+
followForks: true
633+
values:
634+
- ` + pidStr + `
635+
`
636+
637+
kpChecker := ec.NewProcessKprobeChecker("").
638+
WithFunctionName(sm.Full(arch.AddSyscallPrefixTestHelper(t, "sys_read"))).
639+
WithArgs(ec.NewKprobeArgumentListMatcher().
640+
WithOperator(lc.Ordered).
641+
WithValues(
642+
ec.NewKprobeArgumentChecker().WithBytesArg(bc.Full([]byte("hello world"))),
643+
ec.NewKprobeArgumentChecker().WithSizeArg(100),
644+
))
645+
checker := ec.NewUnorderedEventChecker(kpChecker)
646+
647+
runKprobeObjectRead(t, readHook, checker, fd, fd2)
648+
}
649+
608650
// sys_openat trace
609651
func getOpenatChecker(t *testing.T, dir string) ec.MultiEventChecker {
610652
kpChecker := ec.NewProcessKprobeChecker("").

0 commit comments

Comments
 (0)