Skip to content

Commit

Permalink
String matching: Add tests for long pre/postfix
Browse files Browse the repository at this point in the history
Add tests for very long (>256 chars) paths for prefix and postfix
selectors.

[Upstream commit: cf7aceb8]

Signed-off-by: Kevin Sheldrake <[email protected]>
  • Loading branch information
kevsecurity committed Dec 4, 2023
1 parent e9170d9 commit 6285eef
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,25 @@ func TestKprobeObjectFilterPrefixOpen(t *testing.T) {
testKprobeObjectFiltered(t, readHook, getOpenatChecker(t, dir), false, dir, false, syscall.O_RDWR, 0x770)
}

func TestKprobeObjectFilterPrefixOpenSuperLong(t *testing.T) {
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))
dir := t.TempDir()
readHook := testKprobeObjectFilterPrefixOpenHook(pidStr, dir)
firstDir := dir + "/testfoo"
longDir := firstDir + "/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"123456789012345678901234567890123456789012345678901234567890"
if err := os.Mkdir(firstDir, 0755); err != nil {
t.Logf("Mkdir %s failed: %s\n", firstDir, err)
t.Skip()
}
if err := os.Mkdir(longDir, 0755); err != nil {
t.Logf("Mkdir %s failed: %s\n", longDir, err)
t.Skip()
}
testKprobeObjectFiltered(t, readHook, getOpenatChecker(t, longDir), false, longDir, false, syscall.O_RDWR, 0x770)
}

func TestKprobeObjectFilterPrefixOpenMount(t *testing.T) {
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))
dir := t.TempDir()
Expand Down Expand Up @@ -1227,6 +1246,50 @@ func TestKprobeObjectPostfixOpenWithNull(t *testing.T) {
testKprobeObjectPostfixOpen(t, true)
}

func TestKprobeObjectPostfixOpenSuperLong(t *testing.T) {
pidStr := strconv.Itoa(int(observertesthelper.GetMyPid()))
dir := t.TempDir()
readHook := `
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "sys-read"
spec:
kprobes:
- call: "sys_openat"
return: false
syscall: true
args:
- index: 0
type: int
- index: 1
type: "string"
- index: 2
type: "int"
selectors:
- matchPIDs:
- operator: In
followForks: true
values:
- ` + pidStr + `
matchArgs:
- index: 1
operator: "Postfix"
values:
- "` + testKprobeObjectPostfixOpenFileName(false) + `"
`

longDir := dir + "/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"123456789012345678901234567890123456789012345678901234567890"
if err := os.Mkdir(longDir, 0755); err != nil {
t.Logf("Mkdir %s failed: %s\n", longDir, err)
t.Skip()
}

testKprobeObjectFiltered(t, readHook, getOpenatChecker(t, longDir), false, longDir, false, syscall.O_RDWR, 0x770)
}

func testKprobeObjectFilterModeOpenHook(pidStr string, mode int, valueFmt string) string {
return `
apiVersion: cilium.io/v1alpha1
Expand Down

0 comments on commit 6285eef

Please sign in to comment.