Skip to content

Commit

Permalink
pkg/sensors: fix potential issue in stacktrace detection
Browse files Browse the repository at this point in the history
Previous condition was buggy and should have been:
hasStackTrace = hasStackTrace || KernelStackTrace || UserStackTrace
instead of :
hasStackTrace =  KernelStackTrace || UserStackTrace

Using a function simplify this.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Jun 19, 2024
1 parent e66d4fc commit 1bfd8bf
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,6 @@ func addKprobe(funcName string, f *v1alpha1.KProbeSpec, in *addKprobeIn) (id idt
config.Syscall = 0
}

hasStackTrace := false
for _, selector := range f.Selectors {
for _, matchAction := range selector.MatchActions {
hasStackTrace = matchAction.KernelStackTrace || matchAction.UserStackTrace
}
}

// create a new entry on the table, and pass its id to BPF-side
// so that we can do the matching at event-generation time
kprobeEntry := genericKprobe{
Expand All @@ -810,7 +803,7 @@ func addKprobe(funcName string, f *v1alpha1.KProbeSpec, in *addKprobeIn) (id idt
customHandler: in.customHandler,
message: msgField,
tags: tagsField,
hasStackTrace: hasStackTrace,
hasStackTrace: selectorsHaveStackTrace(f.Selectors),
hasRatelimit: selectorsHaveRateLimit(f.Selectors),
}

Expand Down Expand Up @@ -1316,3 +1309,14 @@ func selectorsHaveRateLimit(selectors []v1alpha1.KProbeSelector) bool {
}
return false
}

func selectorsHaveStackTrace(selectors []v1alpha1.KProbeSelector) bool {
for _, selector := range selectors {
for _, matchAction := range selector.MatchActions {
if matchAction.KernelStackTrace || matchAction.UserStackTrace {
return true
}
}
}
return false
}

0 comments on commit 1bfd8bf

Please sign in to comment.