Skip to content

Commit

Permalink
disable (process) ebpf events when to many errors
Browse files Browse the repository at this point in the history
if an invalid opensnitch-procs.o module was loaded, we were flooding
the log with errors.
In these cases stop processing events after 20 errors (random, we should
have no errors).

This may occur if the module is malformed (valid .o ebpf module but
different structs, etc), or when loading modules from other versions.

(cherry picked from commit 0a911ef)
  • Loading branch information
gustavo-iniguez-goya committed Jun 12, 2024
1 parent 362c0da commit 8895d6f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion daemon/procmon/ebpf/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ func initPerfMap(mod *elf.Module) {

func streamEventsWorker(id int, chn chan []byte, lost chan uint64, kernelEvents chan interface{}, execEvents *eventsStore) {
var event execEvent
errors := 0
maxErrors := 20 // we should have no errors.
tooManyErrors := func() bool {
errors++
if errors > maxErrors {
log.Error("[eBPF events] too many errors parsing events from kernel")
log.Error("verify that you're using the correct eBPF modules for this version (%s)", core.Version)
return true
}
return false
}

for {
select {
case <-ctxTasks.Done():
Expand All @@ -159,7 +171,11 @@ func streamEventsWorker(id int, chn chan []byte, lost chan uint64, kernelEvents
log.Debug("Lost ebpf events: %d", l)
case d := <-chn:
if err := binary.Read(bytes.NewBuffer(d), hostByteOrder, &event); err != nil {
log.Error("[eBPF events #%d] error: %s", id, err)
log.Debug("[eBPF events #%d] error: %s", id, err)
if tooManyErrors() {
goto Exit
}

} else {
switch event.Type {
case EV_TYPE_EXEC, EV_TYPE_EXECVEAT:
Expand Down

0 comments on commit 8895d6f

Please sign in to comment.