All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Ilvokhin <d@ilvokhin.com>
To: "Jason A . Donenfeld" <Jason@zx2c4.com>
Cc: wireguard@lists.zx2c4.com, Dmitry Ilvokhin <d@ilvokhin.com>
Subject: [PATCH] wg-quick: darwin: fix set_dns() and del_dns() race
Date: Fri, 18 Sep 2026 17:36:16 +0000	[thread overview]
Message-ID: <20260918173616.358826-1-d@ilvokhin.com> (raw)

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 <d@ilvokhin.com>
---
 src/wg-quick/darwin.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash
index 0179afb..20a21ce 100755
--- a/src/wg-quick/darwin.bash
+++ b/src/wg-quick/darwin.bash
@@ -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=$!
-- 
2.54.0 (Apple Git-157)


             reply	other threads:[~2026-10-05  8:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 17:36 Dmitry Ilvokhin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-09-30 10:30 [PATCH] wg-quick: darwin: fix set_dns() and del_dns() race Dmitry Ilvokhin
2026-10-07 10:21 ` Dmitry Ilvokhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918173616.358826-1-d@ilvokhin.com \
    --to=d@ilvokhin.com \
    --cc=Jason@zx2c4.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.