Skip to content

Commit

Permalink
clean dns ebpf hooks on exit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gustavo-iniguez-goya committed Jan 28, 2024
1 parent c118058 commit 785500c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion daemon/dns/ebpfhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/signal"
"strings"
"syscall"
"time"

"github.com/evilsocket/opensnitch/daemon/core"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 785500c

Please sign in to comment.