Skip to content

Commit

Permalink
ebpf: add a new required dependency field.
Browse files Browse the repository at this point in the history
Marking an event as required will make it so failing to attach it will fail tracee.
Otherwise, tracee will continue to load as usual and log the failure.
Now events can be loaded with partial dependencies.
  • Loading branch information
NDStrahilevitz committed Apr 28, 2022
1 parent 88abde1 commit 6332704
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pkg/ebpf/events_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type probe struct {
type eventDependency struct {
eventID int32
shouldSubmit bool
required bool
}

type dependencies struct {
Expand Down Expand Up @@ -6202,7 +6203,7 @@ var EventsDefinitions = map[int32]EventDefinition{
Name: "container_create",
Probes: []probe{},
Dependencies: dependencies{
events: []eventDependency{{eventID: CgroupMkdirEventID, shouldSubmit: true}},
events: []eventDependency{{eventID: CgroupMkdirEventID, shouldSubmit: true, required: true}},
},
Sets: []string{},
Params: []trace.ArgMeta{
Expand All @@ -6216,7 +6217,7 @@ var EventsDefinitions = map[int32]EventDefinition{
Name: "container_remove",
Probes: []probe{},
Dependencies: dependencies{
events: []eventDependency{{eventID: CgroupRmdirEventID, shouldSubmit: true}},
events: []eventDependency{{eventID: CgroupRmdirEventID, shouldSubmit: true, required: true}},
},
Sets: []string{},
Params: []trace.ArgMeta{
Expand Down Expand Up @@ -6314,7 +6315,7 @@ var EventsDefinitions = map[int32]EventDefinition{
ID32Bit: sys32undefined,
Name: "detect_hooked_syscalls",
Dependencies: dependencies{
events: []eventDependency{{eventID: FinitModuleEventID}, {eventID: PrintSyscallTableEventID}, {eventID: InitModuleEventID}},
events: []eventDependency{{eventID: FinitModuleEventID, required: true}, {eventID: PrintSyscallTableEventID, required: true}, {eventID: InitModuleEventID, required: true}},
},
Sets: []string{},
Params: []trace.ArgMeta{
Expand Down
15 changes: 11 additions & 4 deletions pkg/ebpf/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ type fileExecInfo struct {
}

type eventConfig struct {
submit bool // event should be submitted to userspace
emit bool // event should be emitted to the user
required bool // event must be attached for tracee to function
submit bool // event should be submitted to userspace
emit bool // event should be emitted to the user
}

// Tracee traces system calls and system events using eBPF
Expand Down Expand Up @@ -214,6 +215,9 @@ func (t *Tracee) handleEventsDependencies(e int32, initReq *RequiredInitValues)
if dependentEvent.shouldSubmit {
ec.submit = true
}
if dependentEvent.required {
ec.required = true
}
t.events[dependentEvent.eventID] = ec
t.handleEventsDependencies(dependentEvent.eventID, initReq)
}
Expand Down Expand Up @@ -1052,7 +1056,7 @@ func (t *Tracee) initBPF() error {
}
}

for e := range t.events {
for e, eventConfig := range t.events {
event, ok := EventsDefinitions[e]
if !ok {
continue
Expand Down Expand Up @@ -1083,7 +1087,10 @@ func (t *Tracee) initBPF() error {
_, err = prog.AttachRawTracepoint(tpEvent)
}
if err != nil {
return fmt.Errorf("error attaching event %s: %v", probe.event, err)
if eventConfig.required {
return fmt.Errorf("error attaching required event %s: %v", probe.event, err)
}
t.handleError(fmt.Errorf("error attaching event %s: %v. event was marked as unrequired and tracee will continue to load", probe.event, err))
}
}
}
Expand Down

0 comments on commit 6332704

Please sign in to comment.