Skip to content

Commit 8895d6f

Browse files
disable (process) ebpf events when to many errors
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)
1 parent 362c0da commit 8895d6f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎daemon/procmon/ebpf/events.go‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ func initPerfMap(mod *elf.Module) {
151151

152152
func streamEventsWorker(id int, chn chan []byte, lost chan uint64, kernelEvents chan interface{}, execEvents *eventsStore) {
153153
var event execEvent
154+
errors := 0
155+
maxErrors := 20 // we should have no errors.
156+
tooManyErrors := func() bool {
157+
errors++
158+
if errors > maxErrors {
159+
log.Error("[eBPF events] too many errors parsing events from kernel")
160+
log.Error("verify that you're using the correct eBPF modules for this version (%s)", core.Version)
161+
return true
162+
}
163+
return false
164+
}
165+
154166
for {
155167
select {
156168
case <-ctxTasks.Done():
@@ -159,7 +171,11 @@ func streamEventsWorker(id int, chn chan []byte, lost chan uint64, kernelEvents
159171
log.Debug("Lost ebpf events: %d", l)
160172
case d := <-chn:
161173
if err := binary.Read(bytes.NewBuffer(d), hostByteOrder, &event); err != nil {
162-
log.Error("[eBPF events #%d] error: %s", id, err)
174+
log.Debug("[eBPF events #%d] error: %s", id, err)
175+
if tooManyErrors() {
176+
goto Exit
177+
}
178+
163179
} else {
164180
switch event.Type {
165181
case EV_TYPE_EXEC, EV_TYPE_EXECVEAT:

0 commit comments

Comments
 (0)