clean dns ebpf hooks on exit

We were not reacting to common exit signals, only to kill/interrupt
signals, so the DNS uprobes were never properly removed. Each uprobe
has the PID of the daemon in the identifier, so in theory, there
shouldn't be conflicts, but better clean our probes on exit.

previous to this commit with the daemon running
(and lot of starts/stops):

~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
367

after stopping the daemon:
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
364

~ # > /sys/kernel/debug/tracing/uprobe_events
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

~ # cp opensnitchd-new /usr/bin/opensnitchd ; service opensnitchd start
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
3
~ # service opensnitchd stop
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0
This commit is contained in:
Gustavo Iñiguez Goia 2024-01-28 01:10:00 +01:00
parent c118058dd8
commit 785500cd08
Failed to generate hash of commit

View file

@ -10,6 +10,7 @@ import (
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/evilsocket/opensnitch/daemon/core"
@ -149,7 +150,12 @@ func ListenerEbpf(ebpfModPath string) error {
}
sig := make(chan os.Signal, 1)
exitChannel := make(chan bool)
signal.Notify(sig, os.Interrupt, os.Kill)
signal.Notify(sig,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGKILL,
syscall.SIGQUIT)
for i := 0; i < 5; i++ {
go spawnDNSWorker(i, channel, exitChannel)