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

fix: signature event not triggering if base filtered #3281

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/ebpf/events_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,14 @@ func (t *Tracee) decodeEvents(outerCtx context.Context, sourceChan chan []byte)
}

// If there aren't any policies that need filtering in userland, tracee **may** skip
// this event, as long as there aren't any derivatives that depend on it. Some base
// events (for derivative ones) might not have set related policy bit, thus the need
// to continue with those within the pipeline.
// this event, as long as there aren't any derivatives or signatures that depend on it.
// Some base events (derivative and signatures) might not have set related policy bit,
// thus the need to continue with those within the pipeline.
if t.matchPolicies(&evt) == 0 {
if _, ok := t.eventDerivations[eventId]; !ok {
_, hasDerivation := t.eventDerivations[eventId]
_, hasSignature := t.eventSignatures[eventId]
josedonizetti marked this conversation as resolved.
Show resolved Hide resolved

if !hasDerivation && !hasSignature {
_ = t.stats.EventsFiltered.Increment()
continue
}
Expand Down
19 changes: 13 additions & 6 deletions pkg/ebpf/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Tracee struct {
eventsSorter *sorting.EventsChronologicalSorter
eventProcessor map[events.ID][]func(evt *trace.Event) error
eventDerivations derive.Table
eventSignatures map[events.ID]bool
// Artifacts
fileHashes *lru.Cache[string, fileExecInfo]
capturedFiles map[string]int64
Expand Down Expand Up @@ -181,6 +182,7 @@ func GetCaptureEventsList(cfg config.Config) map[events.ID]eventConfig {

func (t *Tracee) handleEventsDependencies(eventId events.ID, submitMap uint64) {
definition := events.Definitions.Get(eventId)

eDependencies := definition.Dependencies
for _, dependentEvent := range eDependencies.Events {
ec, ok := t.events[dependentEvent.EventID]
Expand All @@ -190,6 +192,10 @@ func (t *Tracee) handleEventsDependencies(eventId events.ID, submitMap uint64) {
}
ec.submit |= submitMap
t.events[dependentEvent.EventID] = ec

if events.IsASignatureEvent(eventId) {
t.eventSignatures[dependentEvent.EventID] = true
yanivagman marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand All @@ -205,12 +211,13 @@ func New(cfg config.Config) (*Tracee, error) {
// Create Tracee

t := &Tracee{
config: cfg,
done: make(chan struct{}),
writtenFiles: make(map[string]string),
readFiles: make(map[string]string),
capturedFiles: make(map[string]int64),
events: GetEssentialEventsList(),
config: cfg,
done: make(chan struct{}),
writtenFiles: make(map[string]string),
readFiles: make(map[string]string),
capturedFiles: make(map[string]int64),
events: GetEssentialEventsList(),
eventSignatures: make(map[events.ID]bool),
}

// Initialize capabilities rings soon
Expand Down
8 changes: 3 additions & 5 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ type Event struct {
Params []trace.ArgMeta
}

func (e *Event) IsASignatureEvent() bool {
for _, s := range e.Sets {
if s == "signatures" {
return true
}
func IsASignatureEvent(id ID) bool {
if id >= StartSignatureID && id <= MaxSignatureID {
return true
}

return false
Expand Down
2 changes: 1 addition & 1 deletion pkg/filters/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (filter *ArgFilter) Parse(filterName string, operatorAndValues string, even
}

// if the event is a signature event, we allow filtering on dynamic argument
if !argFound && !eventDefinition.IsASignatureEvent() {
if !argFound && !events.IsASignatureEvent(id) {
return InvalidEventArgument(argName)
}

Expand Down