public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Aditya Merchant <adityamerchant08@gmail.com>
To: passt-dev@passt.top
Cc: Stefano Brivio <sbrivio@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Paul Holzinger <pholzing@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 3/3] conf: Follow changes to the host nameserver in passt mode, too
Date: Fri,  4 Dec 2026 13:01:19 +0530	[thread overview]
Message-ID: <20261204073119.31027-4-adityamerchant08@gmail.com> (raw)
In-Reply-To: <20261204073119.31027-1-adityamerchant08@gmail.com>

We follow changes to the host's resolv.conf in pasta mode only, as
passt doesn't allow openat() in its seccomp profile. But guests using
--dns-forward are affected just like containers: once the host switches
to another network, or connects to a VPN, their DNS queries keep going
to a stale nameserver until passt restarts.

Allow openat() for passt, too, and drop the check on the mode. We only
use it to open resolv.conf through the read-only, detached copy of its
directory: everything else conf_resolv_watch() needs happens before we
apply seccomp filters, and, once we're sandboxed, there's nothing else
we could open by path anyway. This brings passt to 35 allowed system
calls on x86_64.

Move the AppArmor rule for resolv.conf under /run from the pasta
abstraction to the passt one, which pasta includes, and let passt watch
the same directories as pasta with SELinux.

Extend the dns_host_follow test to check that passt, without a guest,
picks up a new nameserver and forgets a removed one.

Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Link: https://archives.passt.top/passt-dev/20261130013444.57add0dc@elisabeth/
Link: https://archives.passt.top/passt-dev/20261130013439.0a40738a@elisabeth/
Signed-off-by: Aditya Merchant <adityamerchant08@gmail.com>
---
 README.md                           |  2 +-
 conf.c                              |  5 +----
 contrib/apparmor/abstractions/passt |  4 ++++
 contrib/apparmor/abstractions/pasta |  4 ----
 contrib/selinux/passt.te            |  4 ++++
 passt.1                             |  2 +-
 test/pasta_options/dns_host_follow  | 13 +++++++++++++
 7 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 43caf49..2f865fc 100644
--- a/README.md
+++ b/README.md
@@ -291,7 +291,7 @@ speeding up local connections, and usually requiring NAT. _pasta_:
 * ✅ all capabilities dropped, other than `CAP_NET_BIND_SERVICE` (if granted)
 * ✅ with default options, user, mount, IPC, UTS, PID namespaces are detached
 * ✅ no external dependencies (other than a standard C library)
-* ✅ restrictive seccomp profiles (34 syscalls allowed for _passt_, 43 for
+* ✅ restrictive seccomp profiles (35 syscalls allowed for _passt_, 43 for
   _pasta_ on x86_64)
 * ✅ examples of [AppArmor](/passt/tree/contrib/apparmor) and
   [SELinux](/passt/tree/contrib/selinux) profiles available
diff --git a/conf.c b/conf.c
index 7a271ff..925b94d 100644
--- a/conf.c
+++ b/conf.c
@@ -322,7 +322,7 @@ out:
  *
  * Return: 0 on success, negative error code if the file can't be opened
  *
- * #syscalls:pasta openat
+ * #syscalls openat
  */
 static int conf_resolv_update(struct ctx *c)
 {
@@ -413,9 +413,6 @@ void conf_resolv_watch(struct ctx *c)
 	char dir[PATH_MAX], *base;
 	int fd = -1, dir_fd, rc;
 
-	if (c->mode != MODE_PASTA)
-		return;
-
 	if (IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match))
 		c->ip4.dns_host_resolv = false;
 	if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match))
diff --git a/contrib/apparmor/abstractions/passt b/contrib/apparmor/abstractions/passt
index 0aeb19d..d4a65a0 100644
--- a/contrib/apparmor/abstractions/passt
+++ b/contrib/apparmor/abstractions/passt
@@ -17,6 +17,10 @@
 
   include <abstractions/nameservice>		# get_dns(), conf.c
 
+  # Host's resolv.conf in /run, read via a detached copy of its directory,
+  # with paths relative to /run: conf_resolv_watch(), conf_resolv_update()
+  /{NetworkManager,connman,netconfig,resolvconf,systemd/resolve}/resolv.conf r,
+
   capability net_bind_service,			# isolation.c, conf.c
   capability setuid,
   capability setgid,
diff --git a/contrib/apparmor/abstractions/pasta b/contrib/apparmor/abstractions/pasta
index 7ee892b..89fa427 100644
--- a/contrib/apparmor/abstractions/pasta
+++ b/contrib/apparmor/abstractions/pasta
@@ -29,10 +29,6 @@
 
   @{run}/user/@{uid}/**			rw,	# pasta_open_ns()
 
-  # Host's resolv.conf in /run, read via a detached copy of its directory,
-  # with paths relative to /run: conf_resolv_watch(), conf_resolv_update()
-  /{NetworkManager,connman,netconfig,resolvconf,systemd/resolve}/resolv.conf r,
-
   @{PROC}/[0-9]*/ns/			r,	# pasta_netns_quit_init(),
   @{PROC}/[0-9]*/ns/net			r,	# pasta_wait_for_ns(),
   @{PROC}/[0-9]*/ns/user		r,	# conf_pasta_ns()
diff --git a/contrib/selinux/passt.te b/contrib/selinux/passt.te
index e540473..f2628ec 100644
--- a/contrib/selinux/passt.te
+++ b/contrib/selinux/passt.te
@@ -131,6 +131,10 @@ corenet_tcp_sendrecv_all_ports(passt_t)
 corenet_udp_sendrecv_all_ports(passt_t)
 
 sysnet_read_config(passt_t)
+# Watch the directory holding resolv.conf for changes: conf_resolv_watch()
+files_watch_etc_dirs(passt_t)
+networkmanager_watch_pid_dirs(passt_t)
+systemd_resolved_watch_pid_dirs(passt_t)
 
 allow passt_t node_t:icmp_socket { name_bind node_bind };
 allow passt_t port_t:icmp_socket name_bind;
diff --git a/passt.1 b/passt.1
index c743889..bf7a95b 100644
--- a/passt.1
+++ b/passt.1
@@ -287,7 +287,7 @@ Configure the host nameserver which guest or namespace queries to the
 \fB\-\-dns-forward\fR address will be redirected to. This option can
 be specified zero to two times (once for IPv4, once for IPv6).
 By default, the first nameserver from the host's
-\fI/etc/resolv.conf\fR. In pasta mode, on Linux 5.12 or later, this
+\fI/etc/resolv.conf\fR. On Linux 5.12 or later, this
 default follows changes to that file: new DNS flows go to the first
 nameserver listed for each IP version, while existing flows keep their
 target until they expire.
diff --git a/test/pasta_options/dns_host_follow b/test/pasta_options/dns_host_follow
index d8cc232..fa8228f 100644
--- a/test/pasta_options/dns_host_follow
+++ b/test/pasta_options/dns_host_follow
@@ -30,5 +30,18 @@ passt	echo "nameserver 2001:db8::1" > /etc/r && mv /etc/r /etc/resolv.conf
 sleep	1
 passt	touch __DONE__ && wait
 check	grep -q "removed nameserver 192.0.2.2" __LOG_FILE__
+
+test	Host nameserver follows changes to resolv.conf in passt mode
+set	PASST_LOG __STATEDIR__/resolv_passt.log
+set	PIDFILE __STATEDIR__/resolv_passt.pid
+passt	echo "nameserver 192.0.2.1" > /etc/r && mv /etc/r /etc/resolv.conf
+passt	./passt -d -l __PASST_LOG__ -P __PIDFILE__ -s __STATEDIR__/resolv.sock --dns-forward 192.0.2.53
+passt	echo "nameserver 192.0.2.2" > /etc/r && mv /etc/r /etc/resolv.conf
+sleep	1
+passt	echo "nameserver 2001:db8::1" > /etc/r && mv /etc/r /etc/resolv.conf
+sleep	1
+passt	kill $(cat __PIDFILE__)
 passt	umount /etc
 passt	exit
+check	grep -q "new host nameserver 192.0.2.2" __PASST_LOG__
+check	grep -q "removed nameserver 192.0.2.2" __PASST_LOG__
-- 
2.50.1 (Apple Git-155)


  parent reply	other threads:[~2026-12-04  7:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  7:31 [PATCH 0/3] DNS forwarding: follow nameserver changes in passt mode too Aditya Merchant
2026-12-04  7:31 ` [PATCH 1/3] passt.1: Say plainly which nameserver new DNS flows go to Aditya Merchant
2026-12-04 21:35   ` Jon Maloy
2026-12-04  7:31 ` [PATCH 2/3] conf: Forget host nameserver once it's removed from resolv.conf Aditya Merchant
2026-12-04 22:15   ` Jon Maloy
2026-12-04 22:36     ` Stefano Brivio
2026-12-04  7:31 ` Aditya Merchant [this message]
2026-12-04 22:31 ` [PATCH 0/3] DNS forwarding: follow nameserver changes in passt mode too Stefano Brivio

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=20261204073119.31027-4-adityamerchant08@gmail.com \
    --to=adityamerchant08@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=pholzing@redhat.com \
    --cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).