Skip to content

Commit

Permalink
tetragon: Use symbols list in UProbeSpec
Browse files Browse the repository at this point in the history
Currently we define uprobe with path/symbol path, which not
handy when you have more symbols from single path to probe.

Changing the spec so the uprobe is defined by path and array
of symbols, like:

 spec:
   uprobes:
   - path: /bin/bash
     symbols:
     - "_start"
     - "main"
       "builtin_help"

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and jrfastab committed Jan 17, 2024
1 parent 5361282 commit 6796419
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 72 deletions.
3 changes: 2 additions & 1 deletion examples/tracingpolicy/uprobe-binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
spec:
uprobes:
- path: "/lib64/libc.so.6"
symbol: "malloc"
symbols:
- "malloc"
selectors:
- matchBinaries:
- operator: "In"
Expand Down
3 changes: 2 additions & 1 deletion examples/tracingpolicy/uprobe-host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
spec:
uprobes:
- path: "/procRoot/1/root/usr/bin/bash"
symbol: "_start"
symbols:
- "_start"
3 changes: 2 additions & 1 deletion examples/tracingpolicy/uprobe-pid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
spec:
uprobes:
- path: "/bin/bash"
symbol: "readline"
symbols:
- "readline"
selectors:
- matchPIDs:
- operator: In
Expand Down
4 changes: 3 additions & 1 deletion examples/tracingpolicy/uprobe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ metadata:
spec:
uprobes:
- path: "/bin/bash"
symbol: "readline"
symbols:
- "readline"
- "main"
Original file line number Diff line number Diff line change
Expand Up @@ -1781,12 +1781,14 @@ spec:
type: array
type: object
type: array
symbol:
description: Name of the traced symbol
type: string
symbols:
description: List of the traced symbols
items:
type: string
type: array
required:
- path
- symbol
- symbols
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,12 +1781,14 @@ spec:
type: array
type: object
type: array
symbol:
description: Name of the traced symbol
type: string
symbols:
description: List of the traced symbols
items:
type: string
type: array
required:
- path
- symbol
- symbols
type: object
type: array
type: object
Expand Down
4 changes: 2 additions & 2 deletions pkg/k8s/apis/cilium.io/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ type TracepointSpec struct {
type UProbeSpec struct {
// Name of the traced binary
Path string `json:"path"`
// Name of the traced symbol
Symbol string `json:"symbol"`
// List of the traced symbols
Symbols []string `json:"symbols"`
// +kubebuilder:validation:Optional
// A short message of 256 characters max that will be included
// in the event output to inform users what is going on.
Expand Down
5 changes: 5 additions & 0 deletions pkg/k8s/apis/cilium.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 44 additions & 43 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ func createGenericUprobeSensor(
loadProgName = "bpf_generic_uprobe_v53.o"
}

for i := range uprobes {
spec := &uprobes[i]
config := &api.EventConfig{}

for _, spec := range uprobes {
var args []v1alpha1.KProbeArg

if err := isValidUprobeSelectors(spec.Selectors); err != nil {
Expand All @@ -199,46 +196,50 @@ func createGenericUprobeSensor(
logger.GetLogger().WithField("policy-name", policyName).Warnf("TracingPolicy 'message' field too long, truncated to %d characters", TpMaxMessageLen)
}

uprobeEntry := &genericUprobe{
tableId: idtable.UninitializedEntryID,
config: config,
path: spec.Path,
symbol: spec.Symbol,
selectors: uprobeSelectorState,
policyName: policyName,
message: msgField,
for _, sym := range spec.Symbols {
config := &api.EventConfig{}

uprobeEntry := &genericUprobe{
tableId: idtable.UninitializedEntryID,
config: config,
path: spec.Path,
symbol: sym,
selectors: uprobeSelectorState,
policyName: policyName,
message: msgField,
}

uprobeTable.AddEntry(uprobeEntry)
id := uprobeEntry.tableId.ID

uprobeEntry.pinPathPrefix = sensors.PathJoin(sensorPath, fmt.Sprintf("%d", id))
config.FuncId = uint32(id)

pinPath := uprobeEntry.pinPathPrefix
pinProg := sensors.PathJoin(pinPath, "prog")

attachData := &program.UprobeAttachData{
Path: spec.Path,
Symbol: sym,
}

load := program.Builder(
path.Join(option.Config.HubbleLib, loadProgName),
"",
"uprobe/generic_uprobe",
pinProg,
"generic_uprobe").
SetAttachData(attachData).
SetLoaderData(uprobeEntry)

progs = append(progs, load)

configMap := program.MapBuilderPin("config_map", sensors.PathJoin(pinPath, "config_map"), load)
tailCalls := program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)
filterMap := program.MapBuilderPin("filter_map", sensors.PathJoin(pinPath, "filter_map"), load)
selMatchBinariesMap := program.MapBuilderPin("tg_mb_sel_opts", sensors.PathJoin(pinPath, "tg_mb_sel_opts"), load)
maps = append(maps, configMap, tailCalls, filterMap, selMatchBinariesMap)
}

uprobeTable.AddEntry(uprobeEntry)
id := uprobeEntry.tableId.ID

uprobeEntry.pinPathPrefix = sensors.PathJoin(sensorPath, fmt.Sprintf("%d", id))
config.FuncId = uint32(id)

pinPath := uprobeEntry.pinPathPrefix
pinProg := sensors.PathJoin(pinPath, "prog")

attachData := &program.UprobeAttachData{
Path: spec.Path,
Symbol: spec.Symbol,
}

load := program.Builder(
path.Join(option.Config.HubbleLib, loadProgName),
"",
"uprobe/generic_uprobe",
pinProg,
"generic_uprobe").
SetAttachData(attachData).
SetLoaderData(uprobeEntry)

progs = append(progs, load)

configMap := program.MapBuilderPin("config_map", sensors.PathJoin(pinPath, "config_map"), load)
tailCalls := program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)
filterMap := program.MapBuilderPin("filter_map", sensors.PathJoin(pinPath, "filter_map"), load)
selMatchBinariesMap := program.MapBuilderPin("tg_mb_sel_opts", sensors.PathJoin(pinPath, "tg_mb_sel_opts"), load)
maps = append(maps, configMap, tailCalls, filterMap, selMatchBinariesMap)
}

return &sensors.Sensor{
Expand Down
15 changes: 10 additions & 5 deletions pkg/sensors/tracing/uprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ metadata:
spec:
uprobes:
- path: "/bin/bash"
symbol: "main"
symbols:
- "main"
`

var sens []*sensors.Sensor
Expand Down Expand Up @@ -98,7 +99,8 @@ metadata:
spec:
uprobes:
- path: "` + testNop + `"
symbol: "main"
symbols:
- "main"
`

nopConfigHook := []byte(nopHook)
Expand Down Expand Up @@ -148,7 +150,8 @@ metadata:
spec:
uprobes:
- path: "` + path + `"
symbol: "uprobe_test_func"
symbols:
- "uprobe_test_func"
selectors:
- matchPIDs:
- operator: In
Expand Down Expand Up @@ -209,7 +212,8 @@ metadata:
spec:
uprobes:
- path: "` + libUprobe + `"
symbol: "uprobe_test_lib"
symbols:
- "uprobe_test_lib"
selectors:
- matchBinaries:
- operator: "In"
Expand Down Expand Up @@ -280,8 +284,9 @@ metadata:
spec:
uprobes:
- path: "` + testBin + `"
symbol: "do_uprobe"
message: "Uprobe test"
symbols:
- "do_uprobe"
selectors:
- matchBinaries:
- operator: "In"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6796419

Please sign in to comment.