Skip to content

Commit 5bcb17c

Browse files
tetragon: make GetIndex() consistent
With this change, GetIndex() has the same semantic meaning regardless of hook type. It returns the index of the Arg within the spec. This fixes a returnCopy issue where we were overwriting the wrong arg when we merge the arg value after the retprobe event. Signed-off-by: Andy Strohman <[email protected]>
1 parent e3c2f30 commit 5bcb17c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/sensors/tracing/generickprobe.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
744744
var argSigPrinters []argPrinter
745745
var argReturnPrinters []argPrinter
746746
var setRetprobe bool
747-
var argRetprobe *v1alpha1.KProbeArg
747+
var argRetprobe *v1alpha1.KProbeArg // holds pointer to arg for return handler
748+
var argRetprobeIdx int
748749
var allBTFArgs [api.EventConfigMaxArgs][api.MaxBTFArgDepth]api.ConfigBTFArg
749750

750751
errFn := func(err error) (idtable.EntryID, error) {
@@ -790,8 +791,6 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
790791
return errFn(fmt.Errorf("error: '%w'", err))
791792
}
792793

793-
argRetprobe = nil // holds pointer to arg for return handler
794-
795794
addArg := func(j int, a *v1alpha1.KProbeArg, data bool) error {
796795
// First try userspace types
797796
var argType int
@@ -844,6 +843,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
844843
}
845844
if argReturnCopy(argMValue) {
846845
argRetprobe = &f.Args[j]
846+
argRetprobeIdx = j
847847
}
848848
if a.Index > 4 {
849849
return fmt.Errorf("error add arg: ArgType %s Index %d out of bounds",
@@ -855,7 +855,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
855855
eventConfig.RegArg[j] = regArg
856856

857857
argP := argPrinter{
858-
index: int(a.Index),
858+
index: j,
859859
ty: argType,
860860
userType: userArgType,
861861
maxData: a.MaxData,
@@ -934,7 +934,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
934934
argType := gt.GenericTypeFromString(argRetprobe.Type)
935935
eventConfig.ArgReturnCopy = int32(argType)
936936

937-
argP := argPrinter{index: int(argRetprobe.Index), ty: argType, label: argRetprobe.Label}
937+
argP := argPrinter{index: argRetprobeIdx, ty: argType, label: argRetprobe.Label}
938938
argReturnPrinters = append(argReturnPrinters, argP)
939939
} else {
940940
eventConfig.ArgReturnCopy = int32(gt.GenericUnsetType)

pkg/sensors/tracing/genericuprobe.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ func createGenericUprobeSensor(
470470

471471
func addUprobe(spec *v1alpha1.UProbeSpec, ids []idtable.EntryID, in *addUprobeIn) ([]idtable.EntryID, error) {
472472
var argRetprobe *v1alpha1.KProbeArg
473+
var argRetprobeIdx int
473474
var setRetprobe bool
474475

475476
symbols := len(spec.Symbols)
@@ -584,6 +585,7 @@ func addUprobe(spec *v1alpha1.UProbeSpec, ids []idtable.EntryID, in *addUprobeIn
584585
}
585586
if argReturnCopy(argMValue) {
586587
argRetprobe = &spec.Args[i]
588+
argRetprobeIdx = i
587589
}
588590
if a.Index > 4 {
589591
return fmt.Errorf("error add arg: ArgType %s Index %d out of bounds",
@@ -661,7 +663,7 @@ func addUprobe(spec *v1alpha1.UProbeSpec, ids []idtable.EntryID, in *addUprobeIn
661663
argType := gt.GenericTypeFromString(argRetprobe.Type)
662664
eventConfig.ArgReturnCopy = int32(argType)
663665

664-
argP := argPrinter{index: int(argRetprobe.Index), ty: argType, label: argRetprobe.Label}
666+
argP := argPrinter{index: argRetprobeIdx, ty: argType, label: argRetprobe.Label}
665667
argReturnPrinters = append(argReturnPrinters, argP)
666668
} else {
667669
eventConfig.ArgReturnCopy = int32(gt.GenericUnsetType)

pkg/sensors/tracing/genericusdt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func addUsdt(spec *v1alpha1.UsdtSpec, in *addUsdtIn, ids []idtable.EntryID) ([]i
353353
config.ArgType[cfgIdx] = int32(argType)
354354

355355
argPrinters = append(argPrinters,
356-
argPrinter{index: int(arg.Index), ty: argType, label: arg.Label},
356+
argPrinter{index: cfgIdx, ty: argType, label: arg.Label},
357357
)
358358
}
359359
config.BTFArg = allBTFArgs

0 commit comments

Comments
 (0)