Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Florian Bausch <fbausch@ernw.de>
To: wireguard@lists.zx2c4.com
Subject: [PATCH] wg-tools: Fix too strict file permissions on resolv.conf
Date: Sun, 5 Feb 2023 20:19:20 +0100	[thread overview]
Message-ID: <90cadce0-51e9-d9f3-4b27-084f49e99f1c@ernw.de> (raw)

Hi,

I hardened my system by setting a strict umask of 077 in 
/etc/login.defs. However, this breaks DNS as soon as wg-quick is used to 
bring up a WireGuard tunnel. This is, because the strict umask value 
will be applied to /etc/resolv.conf (at least if the DNS hatchet is 
used) and therefore, unprivileged processes are not able to read 
/etc/resolv.conf.

While the behavior can be worked around by setting umask in other 
places, the fix below would prevent this behavior to occur. The umask 
022 is applied before creating the new /etc/resolv.conf in the DNS hatchet.

Kind regards

---
  contrib/dns-hatchet/hatchet.bash | 1 +
  1 file changed, 1 insertion(+)

diff --git a/contrib/dns-hatchet/hatchet.bash 
b/contrib/dns-hatchet/hatchet.bash
index bc4d090..807a14a 100644
--- a/contrib/dns-hatchet/hatchet.bash
+++ b/contrib/dns-hatchet/hatchet.bash
@@ -20,6 +20,7 @@ set_dns() {
  		[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
  		} | unshare -m --propagation shared bash -c "$(cat <<-_EOF
  			set -e
+			umask 022
  			context="\$(stat -c %C /etc/resolv.conf 2>/dev/null)" || unset context
  			mount --make-private /dev/shm
  			mount -t tmpfs none /dev/shm
-- 
2.39.1


             reply	other threads:[~2023-02-07  4:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-05 19:19 Florian Bausch [this message]
2023-02-07 22:54 ` Jason A. Donenfeld
2023-02-15 12:54   ` Florian Bausch
2023-02-15 12:55     ` Florian Bausch

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=90cadce0-51e9-d9f3-4b27-084f49e99f1c@ernw.de \
    --to=fbausch@ernw.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).