Skip to content

Commit

Permalink
Don't print raw_syscall if event exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yanivagman committed Aug 3, 2020
1 parent 2d4ba36 commit 3137927
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tracee/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (t *Tracee) processRawEvent(done <-chan struct{}, in <-chan RawEvent) (<-ch
defer close(out)
defer close(errc)
for rawEvent := range in {
if !t.shouldProcessEvent(rawEvent) {
continue
}
err := t.processEvent(&rawEvent.Ctx, rawEvent.RawArgs)
if err != nil {
errc <- err
Expand All @@ -110,7 +113,7 @@ func (t *Tracee) prepareEventForPrint(done <-chan struct{}, in <-chan RawEvent)
defer close(out)
defer close(errc)
for rawEvent := range in {
if !t.shouldPrintEvent(rawEvent.Ctx.EventID) {
if !t.shouldPrintEvent(rawEvent) {
continue
}
err := t.prepareArgsForPrint(&rawEvent.Ctx, rawEvent.RawArgs)
Expand Down
38 changes: 32 additions & 6 deletions tracee/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,6 @@ func boolToUInt32(b bool) uint32 {
return uint32(0)
}

// shouldPrintEvent decides whether or not the given event id should be printed to the output
func (t *Tracee) shouldPrintEvent(e int32) bool {
// Only print events requested by the user
return t.eventsToTrace[e]
}

func copyFileByPath(src, dst string) error {
sourceFileStat, err := os.Stat(src)
if err != nil {
Expand Down Expand Up @@ -424,6 +418,11 @@ func (t *Tracee) handleError(err error) {
t.printer.Error(err)
}

// shouldProcessEvent decides whether or not to drop an event before further processing it
func (t *Tracee) shouldProcessEvent(e RawEvent) bool {
return true
}

func (t *Tracee) processEvent(ctx *context, args map[argTag]interface{}) error {
switch ctx.EventID {
case SecurityBprmCheckEventID:
Expand Down Expand Up @@ -465,6 +464,33 @@ func (t *Tracee) processEvent(ctx *context, args map[argTag]interface{}) error {
return nil
}

// shouldPrintEvent decides whether or not the given event id should be printed to the output
func (t *Tracee) shouldPrintEvent(e RawEvent) bool {
// Only print events requested by the user
if !t.eventsToTrace[e.Ctx.EventID] {
return false
}
switch e.Ctx.EventID {
case RawSyscallsEventID:
if id, isInt32 := e.RawArgs[TagSyscall].(int32); isInt32 {
event, isKnown := EventsIDToEvent[id]
if !isKnown {
t.handleError(fmt.Errorf("raw_syscalls: unknown syscall id: %d", id))
return false
}
if event.Probes[0].attach != sysCall {
t.handleError(fmt.Errorf("raw_syscalls: unknown syscall id: %d", id))
return false
}
if event.Name != "reserved" {
// We already monitor this system call by another event
return false
}
}
}
return true
}

func (t *Tracee) prepareArgsForPrint(ctx *context, args map[argTag]interface{}) error {
switch ctx.EventID {
case RawSyscallsEventID, CapCapableEventID:
Expand Down

0 comments on commit 3137927

Please sign in to comment.