Skip to content

Commit 430e8c1

Browse files
andrewstrohmankkourt
authored andcommitted
tetragon: Add additional returnCopy test
This test confirms that we don't confuse the meaning of index. Arguments have a position (index) within the args section of a tracing policy spec. The arg's position defined within the spec is not related to the arg's position (index) within the function signature or tracepoint that is being hooked. We had a bug where we confused the meaning of index. Retprobes need to overwrite a argument value that not available at function entry. We locate the argument which needs to be overwritten by referencing its position within the tracing policy spec. The bug happened because we overwrote based on arg's position within the function signature. As such, returnCopy only worked as expected when the user defined the args in the tracing policy spec in the same order as they appear in the function/tracepoint signature. This returnCopy test is constructed such that the configured argument's index within the spec does not correspond to the arguments position within the function signature. Signed-off-by: Andy Strohman <astrohma@isovalent.com>
1 parent 3368d2f commit 430e8c1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

pkg/sensors/tracing/kprobe_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,52 @@ spec:
555555
runKprobeObjectRead(t, readHook, checker, fd, fd2)
556556
}
557557

558+
func TestKprobeObjectReadIdxMismatch(t *testing.T) {
559+
fd, fd2, fdString := createTestFile(t)
560+
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))
561+
readHook := `
562+
apiVersion: cilium.io/v1alpha1
563+
kind: TracingPolicy
564+
metadata:
565+
name: "sys-read"
566+
spec:
567+
kprobes:
568+
- call: "sys_read"
569+
syscall: true
570+
args:
571+
- index: 1
572+
type: "char_buf"
573+
returnCopy: true
574+
- index: 2
575+
type: "size_t"
576+
- index: 0
577+
type: "int"
578+
selectors:
579+
- matchPIDs:
580+
- operator: In
581+
followForks: true
582+
values:
583+
- ` + pidStr + `
584+
matchArgs:
585+
- index: 0
586+
operator: "Equal"
587+
values:
588+
- "` + fdString + `"`
589+
590+
kpChecker := ec.NewProcessKprobeChecker("").
591+
WithFunctionName(sm.Full(arch.AddSyscallPrefixTestHelper(t, "sys_read"))).
592+
WithArgs(ec.NewKprobeArgumentListMatcher().
593+
WithOperator(lc.Ordered).
594+
WithValues(
595+
ec.NewKprobeArgumentChecker().WithBytesArg(bc.Full([]byte("hello world"))),
596+
ec.NewKprobeArgumentChecker().WithSizeArg(100),
597+
ec.NewKprobeArgumentChecker().WithIntArg(int32(fd2)),
598+
))
599+
checker := ec.NewUnorderedEventChecker(kpChecker)
600+
601+
runKprobeObjectRead(t, readHook, checker, fd, fd2)
602+
}
603+
558604
func TestKprobeObjectReadReturn(t *testing.T) {
559605
fd, fd2, fdString := createTestFile(t)
560606
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))

0 commit comments

Comments
 (0)