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 14, 2024
1 parent 4877cfd commit 6765233
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 @@ -765,13 +765,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 @@ -790,7 +783,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),
}

// Parse Filters into kernel filter logic
Expand Down Expand Up @@ -1274,3 +1267,14 @@ func retprobeMerge(prev pendingEvent, curr pendingEvent) *tracing.MsgGenericKpro
func (k *observerKprobeSensor) LoadProbe(args sensors.LoadProbeArgs) error {
return loadGenericKprobeSensor(args.BPFDir, args.Load, args.Verbose)
}

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 6765233

Please sign in to comment.