From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id AE12424CE1; Thu, 11 Dec 2025 16:26:40 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 5B0D324C44; Thu, 11 Dec 2025 16:26:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_MISSING,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) by atuin.qyliss.net (Postfix) with ESMTPS id 94A7824C43 for ; Thu, 11 Dec 2025 16:26:37 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 6C31CEC0093; Thu, 11 Dec 2025 11:26:35 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 11 Dec 2025 11:26:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1765470395; x= 1765556795; bh=gNrlGOPge0Y1sKKKGbEAWm3as0nQv4EtPKYY1nzQoo4=; b=E XSOxc/PYUEQ7ltguppLjRNyXsTzQQrQhj5hYJnIRyTXUFAyk2MmSxFY0OgPhZO5+ T51w+qrjV4DBzt3kK5a6WcNzTbGs6z0qVLf7iMOj1bhT+xZq2VaTXz6lHTPPYMaX JQ/7H2pHZaLqBmEIF2bMaX1RZ7SUWroRhCUBuyVxN7YiQUnzo/ihOjgYXpN7zlIH l0l8S0aMC8qb8Z9XL3EpjOQzSGHVdJY03rzNjRglYt8XJYXMYLgZizXZGrI8X9Be OSmI50HepfW6fa0gHxSofDQ32s3EHvd9TvgWgDlKQHyrTWEBIoQzzkpcEQ7woSto oHOEdq0ZyckCVH0Uc5kGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1765470395; x=1765556795; bh=g NrlGOPge0Y1sKKKGbEAWm3as0nQv4EtPKYY1nzQoo4=; b=M1Ww+0fscovR/Gn/a 3IiGQaHkoJDBfUOcQ9tkaVagH2RgBukkMIhzVXbBPQFshRewrEDNS9AFyN9VgJga 6egh9raFkhz7lziXd1nSOViCCQgNydjF9kuQMzWm6+1eDOKhLwwiiISG8RcCxDjn qgeZXbPtrOBp8cADcwumh5YO36/7XgybUv0R5tVCfuf3h7INCMiNZPi2xdlmxq22 7EnzppSzvxE7tq+farjwUI+YwAIQYmcPNi6sqOiRdMPWZAmgTG4QMSMUw4ZxC78m m9sYBRh2tyqU9RNA9mcURfnovdvAC0rSTBNZZLo2HtKSyCQGQI1OvJZxYq+031ZG oU1jA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvheejkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetlhihshhsrgcu tfhoshhsuceohhhisegrlhihshhsrgdrihhsqeenucggtffrrghtthgvrhhnpeethfegie ffffelteduueeltdelueethfeuteevieetuefggeefuddvlefgtdefvdenucffohhmrghi nhepshhpvggtthhruhhmqdhoshdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehhihesrghlhihsshgrrdhishdpnhgspghrtghpthht ohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepuggvmhhiohgsvghnohhurh esghhmrghilhdrtghomhdprhgtphhtthhopeguvghvvghlsehsphgvtghtrhhumhdqohhs rdhorhhg X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Dec 2025 11:26:35 -0500 (EST) Received: by fw12.qyliss.net (Postfix, from userid 1000) id 8C6A76F748EA; Thu, 11 Dec 2025 17:26:23 +0100 (CET) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH v2 5/8] host/rootfs: create a per-VM user namespace Date: Thu, 11 Dec 2025 17:21:47 +0100 Message-ID: <20251211162145.124509-10-hi@alyssa.is> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251211162145.124509-2-hi@alyssa.is> References: <20251211162145.124509-2-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RYFMVLUHDUGPWDRBVU6FNC2QVYGHLETI X-Message-ID-Hash: RYFMVLUHDUGPWDRBVU6FNC2QVYGHLETI X-MailFrom: hi@alyssa.is X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Demi Marie Obenour X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The document portal has to be root to mount its fuse filesystem. This needs to be a shared namespace because virtiofsd needs to be in the same mount namespace as the document portal so that it sees the fuse filesystem, so we create a per-VM persistent user namespace. Signed-off-by: Alyssa Ross --- v2: put nsfs bind mounts into a shared directory, to make unmounting nicer. v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251210124757.1080443-5-hi@alyssa.is/ .../vm-services/template/data/service/dbus/run | 2 +- .../template/data/service/vhost-user-fs/run | 2 +- host/rootfs/image/usr/bin/create-vm-dependencies | 13 +++++++++---- host/rootfs/image/usr/bin/run-appimage | 5 ++--- host/rootfs/image/usr/bin/run-flatpak | 5 ++--- host/rootfs/image/usr/bin/spectrum-update | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/dbus/run b/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/dbus/run index 20f1daff..f4c78f71 100755 --- a/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/dbus/run +++ b/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/dbus/run @@ -15,7 +15,7 @@ fdmove -c 3 0 redirfd -r 0 /dev/null getcwd -E dir -nsenter --mount=/run/vm/by-id/${VM}/mount +nsenter --mount=/run/vm/by-id/${VM}/ns/mnt unshare --cgroup --ipc --net --uts diff --git a/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/vhost-user-fs/run b/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/vhost-user-fs/run index 79830a00..1936175e 100755 --- a/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/vhost-user-fs/run +++ b/host/rootfs/image/etc/s6-linux-init/run-image/service/vm-services/template/data/service/vhost-user-fs/run @@ -12,7 +12,7 @@ export TMPDIR /run importas -i VM VM -nsenter --mount=/run/vm/by-id/${VM}/mount +nsenter --mount=/run/vm/by-id/${VM}/ns/mnt unshare -U --map-user 1000 --map-group 1000 --uts --ipc --cgroup virtiofsd --fd 3 --shared-dir /run/vm/by-id/${VM}/fs diff --git a/host/rootfs/image/usr/bin/create-vm-dependencies b/host/rootfs/image/usr/bin/create-vm-dependencies index d4a10ab4..34dace4b 100755 --- a/host/rootfs/image/usr/bin/create-vm-dependencies +++ b/host/rootfs/image/usr/bin/create-vm-dependencies @@ -2,18 +2,23 @@ # SPDX-License-Identifier: EUPL-1.2+ # SPDX-FileCopyrightText: 2024-2025 Alyssa Ross -if { touch /run/vm/by-id/${1}/mount } -if { mount --make-private --bind /run/vm/by-id/${1}/mount /run/vm/by-id/${1}/mount } - if { mkdir -p /run/vm/by-id/${1}/doc-run/doc /run/vm/by-id/${1}/fs/config /run/vm/by-id/${1}/fs/doc + /run/vm/by-id/${1}/ns } +if { mount --make-private --rbind /run/vm/by-id/${1}/ns /run/vm/by-id/${1}/ns } +if { touch /run/vm/by-id/${1}/ns/mnt /run/vm/by-id/${1}/ns/user } + if { - unshare --propagation=slave --mount=/run/vm/by-id/${1}/mount + unshare --propagation=slave + --map-users all + --map-groups all + --mount=/run/vm/by-id/${1}/ns/mnt + --user=/run/vm/by-id/${1}/ns/user if { mount --make-shared --rbind /run/vm/by-id/${1} /run/vm/by-id/${1} } diff --git a/host/rootfs/image/usr/bin/run-appimage b/host/rootfs/image/usr/bin/run-appimage index 47cab4c5..44a683c3 100755 --- a/host/rootfs/image/usr/bin/run-appimage +++ b/host/rootfs/image/usr/bin/run-appimage @@ -19,7 +19,7 @@ if { ln -s /run/configs/${id} ${dir}/config } if { create-vm-dependencies $id } if { - nsenter --mount=${dir}/mount + nsenter --mount=${dir}/ns/mnt cd ${dir}/fs/config if { redirfd -w 1 type echo appimage } if { touch run } @@ -42,6 +42,5 @@ fdclose 3 if { s6-instance-delete /run/service/vm-services $id } -if { umount ${dir}/mount } # mount namespace -if { umount ${dir}/mount } # private bind mount +if { umount -R ${dir}/ns } rm -r $dir /run/configs/${id} diff --git a/host/rootfs/image/usr/bin/run-flatpak b/host/rootfs/image/usr/bin/run-flatpak index bb366735..07cfc262 100755 --- a/host/rootfs/image/usr/bin/run-flatpak +++ b/host/rootfs/image/usr/bin/run-flatpak @@ -22,7 +22,7 @@ if { if { create-vm-dependencies $id } if { - nsenter --mount=${dir}/mount + nsenter --mount=${dir}/ns/mnt cd ${dir}/fs/config if { redirfd -w 1 type echo flatpak } mount-flatpak $@ @@ -44,6 +44,5 @@ if { if { s6-instance-delete -- /run/service/vm-services $id } -if { umount ${dir}/mount } # mount namespace -if { umount ${dir}/mount } # private bind mount +if { umount -R ${dir}/ns } rm -r $dir /run/configs/${id} diff --git a/host/rootfs/image/usr/bin/spectrum-update b/host/rootfs/image/usr/bin/spectrum-update index b1517a6c..be99c9da 100755 --- a/host/rootfs/image/usr/bin/spectrum-update +++ b/host/rootfs/image/usr/bin/spectrum-update @@ -50,7 +50,7 @@ foreground { cp -- /etc/systemd/import-pubring.gpg /run/vm/by-id/${update_vm_id}/fs/etc/systemd } - nsenter --mount=/run/vm/by-id/${update_vm_id}/mount + nsenter --mount=/run/vm/by-id/${update_vm_id}/ns/mnt cd $1 # If the directory is already mounted, unmount it. This prevents a -- 2.51.0