Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tetragon: assorted fixes #2926

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/observer/observertesthelper/observer_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func loadExporter(tb testing.TB, ctx context.Context, obs *observer.Observer, op
})

cgrouprate.NewCgroupRate(ctx, processManager, base.CgroupRateMap, &option.Config.CgroupRate)
base.ConfigCgroupRate(&option.Config.CgroupRate)
return nil
}

Expand Down
26 changes: 11 additions & 15 deletions pkg/sensors/tracing/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path"
"strings"
"sync"
"sync/atomic"

"github.com/cilium/tetragon/pkg/arch"
"github.com/cilium/tetragon/pkg/bpf"
Expand Down Expand Up @@ -95,8 +94,7 @@ func (kp *enforcerPolicy) PolicyHandler(
}
}
if len(spec.Enforcers) > 0 {
name := fmt.Sprintf("enforcer-sensor-%d", atomic.AddUint64(&sensorCounter, 1))
return kp.createEnforcerSensor(spec.Enforcers, spec.Lists, spec.Options, name, policy.TpName())
return kp.createEnforcerSensor(spec.Enforcers, spec.Lists, spec.Options, policy.TpName())
}

return nil, nil
Expand Down Expand Up @@ -185,7 +183,6 @@ func (kp *enforcerPolicy) createEnforcerSensor(
enforcers []v1alpha1.EnforcerSpec,
lists []v1alpha1.ListSpec,
opts []v1alpha1.OptionSpec,
name string,
policyName string,
) (*sensors.Sensor, error) {

Expand Down Expand Up @@ -276,7 +273,6 @@ func (kp *enforcerPolicy) createEnforcerSensor(
return nil, err
}

pinPath := sensors.PathJoin(name, "enforcer_kprobe")
switch overrideMethod {
case OverrideMethodReturn:
useMulti := !specOpts.DisableKprobeMulti && !option.Config.DisableKprobeMulti && bpf.HasKprobeMulti()
Expand All @@ -292,9 +288,9 @@ func (kp *enforcerPolicy) createEnforcerSensor(
path.Join(option.Config.HubbleLib, prog),
attach,
label,
pinPath,
"kprobe",
"enforcer").
SetLoaderData(name)
SetLoaderData(policyName)

progs = append(progs, load)
case OverrideMethodFmodRet:
Expand All @@ -305,9 +301,9 @@ func (kp *enforcerPolicy) createEnforcerSensor(
path.Join(option.Config.HubbleLib, "bpf_fmodret_enforcer.o"),
syscallSym,
"fmod_ret/security_task_prctl",
pinPath,
fmt.Sprintf("fmod_ret_%s", syscallSym),
"enforcer").
SetLoaderData(name)
SetLoaderData(policyName)
progs = append(progs, load)
}
default:
Expand All @@ -319,22 +315,22 @@ func (kp *enforcerPolicy) createEnforcerSensor(

maps = append(maps, enforcerDataMap)

if ok := kp.enforcerAdd(name, kh); !ok {
return nil, fmt.Errorf("failed to add enforcer: '%s'", name)
if ok := kp.enforcerAdd(policyName, kh); !ok {
return nil, fmt.Errorf("failed to add enforcer: '%s'", policyName)
}

logger.GetLogger().Infof("Added enforcer sensor '%s'", name)
logger.GetLogger().Infof("Added enforcer sensor '%s'", policyName)

return &sensors.Sensor{
Name: "__enforcer__",
Progs: progs,
Maps: maps,
Policy: policyName,
PostUnloadHook: func() error {
if ok := kp.enforcerDel(name); !ok {
logger.GetLogger().Infof("Failed to clean up enforcer sensor '%s'", name)
if ok := kp.enforcerDel(policyName); !ok {
logger.GetLogger().Infof("Failed to clean up enforcer sensor '%s'", policyName)
} else {
logger.GetLogger().Infof("Cleaned up enforcer sensor '%s'", name)
logger.GetLogger().Infof("Cleaned up enforcer sensor '%s'", policyName)
}
return nil
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ func createMultiKprobeSensor(policyName string, multiIDs []idtable.EntryID, has
enforcerDataMap := enforcerMap(load)
if has.enforcer {
enforcerDataMap.SetMaxEntries(enforcerMapMaxEntries)
maps = append(maps, enforcerDataMap)
}
maps = append(maps, enforcerDataMap)

filterMap.SetMaxEntries(len(multiIDs))
configMap.SetMaxEntries(len(multiIDs))
Expand Down Expand Up @@ -960,8 +960,8 @@ func createKprobeSensorFromEntry(kprobeEntry *genericKprobe,
enforcerDataMap := enforcerMap(load)
if has.enforcer {
enforcerDataMap.SetMaxEntries(enforcerMapMaxEntries)
maps = append(maps, enforcerDataMap)
}
maps = append(maps, enforcerDataMap)

overrideTasksMap := program.MapBuilderProgram("override_tasks", load)
if has.override {
Expand Down
2 changes: 0 additions & 2 deletions pkg/sensors/tracing/generictracepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ var (
genericTracepointTable = tracepointTable{}

tracepointLog logrus.FieldLogger

sensorCounter uint64
)

type observerTracepointSensor struct {
Expand Down
5 changes: 1 addition & 4 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"path"
"sync/atomic"

"github.com/cilium/ebpf"
"github.com/cilium/tetragon/pkg/api/ops"
Expand Down Expand Up @@ -493,7 +492,5 @@ func (k *observerUprobeSensor) PolicyHandler(
return nil, fmt.Errorf("uprobe sensor does not implement policy filtering")
}

name := fmt.Sprintf("gup-sensor-%d", atomic.AddUint64(&sensorCounter, 1))
policyName := p.TpName()
return createGenericUprobeSensor(name, spec, policyName)
return createGenericUprobeSensor("generic_uprobe", spec, p.TpName())
}
9 changes: 3 additions & 6 deletions pkg/sensors/tracing/policyhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package tracing
import (
"errors"
"fmt"
"sync/atomic"

"github.com/cilium/tetragon/pkg/eventhandler"
"github.com/cilium/tetragon/pkg/policyfilter"
Expand Down Expand Up @@ -44,20 +43,18 @@ func (h policyHandler) PolicyHandler(

handler := eventhandler.GetCustomEventhandler(policy)
if len(spec.KProbes) > 0 {
name := fmt.Sprintf("gkp-sensor-%d", atomic.AddUint64(&sensorCounter, 1))
name := "generic_kprobe"
err := preValidateKprobes(name, spec.KProbes, spec.Lists)
if err != nil {
return nil, fmt.Errorf("validation failed: %w", err)
}
return createGenericKprobeSensor(spec, name, policyID, policyName, handler)
}
if len(spec.Tracepoints) > 0 {
name := fmt.Sprintf("gtp-sensor-%d", atomic.AddUint64(&sensorCounter, 1))
return createGenericTracepointSensor(spec, name, policyID, policyName, handler)
return createGenericTracepointSensor(spec, "generic_tracepoint", policyID, policyName, handler)
}
if len(spec.LsmHooks) > 0 {
name := fmt.Sprintf("glsm-sensor-%d", atomic.AddUint64(&sensorCounter, 1))
return createGenericLsmSensor(spec, name, policyID, policyName)
return createGenericLsmSensor(spec, "generic_lsm", policyID, policyName)
}
return nil, nil
}
Loading