From 1bfd8bfeada23d48734fe1efaa781e5f7c953961 Mon Sep 17 00:00:00 2001 From: Mahe Tardy Date: Fri, 14 Jun 2024 12:43:50 +0200 Subject: [PATCH] pkg/sensors: fix potential issue in stacktrace detection 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 --- pkg/sensors/tracing/generickprobe.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/sensors/tracing/generickprobe.go b/pkg/sensors/tracing/generickprobe.go index f738e24dd4d..4917e480643 100644 --- a/pkg/sensors/tracing/generickprobe.go +++ b/pkg/sensors/tracing/generickprobe.go @@ -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{ @@ -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), } @@ -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 +}