wg-quick: darwin: fix set_dns() and del_dns() race
PATCH 1/1 wg-quick: darwin: fix set_dns() and del_dns() race
The monitor deamon restores the DNS servers by running del_dns() from its INT, TERM and EXIT trap. Every route event also schedules an ALRM 2 seconds later, and the ALRM trap runs set_dns().
If ALRM arrives during cleanup, set_dns() can run in the middle of del_dns(), and the DNS servers may not be restored after the WireGuard interface is removed.
Ignore ALRM in cleanup signal handler to avoid this race.
Signed-off-by Dmitry Ilvokhin <[email protected]>
--- src/wg-quick/darwin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/wg-quick/darwin.bash +1 -1
@@ -323,7 +323,7 @@ del_dns() { monitor_daemon() { echo "[+] Backgrounding route monitor" >&2 - (trap 'del_routes; del_dns; exit 0' INT TERM EXIT + (trap 'trap "" ALRM; del_routes; del_dns; exit 0' INT TERM EXIT exec >/dev/null 2>&1 exec 19< <(exec route -n monitor) local event bpid=$BASHPID mpid=$!
Signature · 1 line
2.54.0 (Apple Git-157)