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 B57F243A0; Mon, 01 Dec 2025 17:07:24 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 0A6144391; Mon, 01 Dec 2025 17:07:22 +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 fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) by atuin.qyliss.net (Postfix) with ESMTPS id 5DC74430C for ; Mon, 01 Dec 2025 17:07:20 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 75AC21400277; Mon, 1 Dec 2025 12:07:18 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Mon, 01 Dec 2025 12:07:18 -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=1764608838; x= 1764695238; bh=JRdKCrAcAW6QdyNjj3K+ekmrjtjtohYZxaUCfe/5I0s=; b=m Gh1+W8IuHenlOYstgxFvhcXb3YzTDiv2HqKVFxMXwHMRh74vYA+RPaMyTul/0/W5 Kx67tuVUPD1NWliPD83Y6tTDmr65jEUMTgXPJtDB7Yh6OUWSmxvghBtlRyXfBSM9 duiCUl/MiexXZ9bMpLLGnrOGa1H5T9YS2Zc23YcCCWk3TnhXqdfydLnNms1YI9BU hnuSOUzppSO6dKTVcilZX/A+cMSiZFSyVtzPa3KdBmhj50qioRUgr/3IqU+rlbtd S24tJohzQMNqcpGg3vuWA1GSFd4awMTF9XLngXJBLNUnTPhyB5UmwCEbnsAru0is AGNXsoopz+TEYZ/OceXpA== 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=1764608838; x=1764695238; bh=J RdKCrAcAW6QdyNjj3K+ekmrjtjtohYZxaUCfe/5I0s=; b=blBqPyBsY19iKG/6p 9njsqOT6as7IzKU9kcCzK1p+cIXnyTY3y0KjAralF7Hu98jdPqwlFWspJ0qcPRHW v5N5fHKEZC0R2je1U73saMHQtRm8PEv754pG/2oALhn+n9u79sYAddQEHPiVsjM8 tasAw8jpKoPdJSEIJn3VtPqSrx+8uLKyYDskwPZAKtYWxdZqUNLURLGtyP9OrwH5 KThP85VrK0kUgGWw6pNr5ej1U7dSpcQvlcS/JaChg9eTQY+4z8r3+CU0YNqdNG6T 9OmyuOYhWfnIVI1PZ52dBbpcrzoR5s8W8JeTVKs78/6VABuXiQpGAEcdJr4fGZ+b S5H+A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvheekvdeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlhihsshgr ucftohhsshcuoehhihesrghlhihsshgrrdhisheqnecuggftrfgrthhtvghrnheptefhge eiffffleetudeuledtleeutefhueetveeiteeugfegfeduvdelgfdtfedvnecuffhomhgr ihhnpehsphgvtghtrhhumhdqohhsrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhephhhisegrlhihshhsrgdrihhspdhnsggprhgtphht thhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeguvghmihhosggvnhhouh hrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepuggvvhgvlhesshhpvggtthhruhhmqdho shdrohhrgh X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Dec 2025 12:07:17 -0500 (EST) Received: by fw12.qyliss.net (Postfix, from userid 1000) id AF6D23FB50F3; Mon, 01 Dec 2025 18:07:06 +0100 (CET) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH v2 3/6] host/rootfs: create a per-VM mount namespace Date: Mon, 1 Dec 2025 18:04:03 +0100 Message-ID: <20251201170458.4186683-5-hi@alyssa.is> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251201170458.4186683-1-hi@alyssa.is> References: <20251201170458.4186683-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EZNOQ4F2ZR5YAMWOS3HUSBCGLIM3SSKU X-Message-ID-Hash: EZNOQ4F2ZR5YAMWOS3HUSBCGLIM3SSKU 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: This will solve the problem of mounts for VMs being very annoying to clean up, as evidenced in run-appimage. It was looking to be even worse for Flatpak. Signed-off-by: Alyssa Ross --- v2: Fix spectrum-update by unsharing with slave propagation instead of private and entering the namespace before setting up mounts. v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251201044534.977524-3-hi@alyssa.is/ .../template/data/service/dbus/run | 2 ++ .../template/data/service/vhost-user-fs/run | 6 +---- .../image/usr/bin/create-vm-dependencies | 26 ++++++++++++++++--- host/rootfs/image/usr/bin/run-appimage | 25 +++++++++--------- host/rootfs/image/usr/bin/spectrum-update | 3 +++ 5 files changed, 40 insertions(+), 22 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 351fc68..9b23192 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 @@ -4,6 +4,8 @@ importas -i VM VM +nsenter --mount=${VM}/mount + dbus-daemon --config-file /usr/share/dbus-1/session.conf --print-address 3 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 5d5ad7d..a9bbd8e 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 @@ -10,10 +10,6 @@ redirfd -r 0 /dev/null export TMPDIR /run -# The VM should not be able to write directly into a tmpfs, but there -# can be writable block-based bind mounted subdirectories. -unshare -m --propagation slave importas -i VM VM -if { mount --rbind -o ro ${VM}/fs ${VM}/fs } - +nsenter --mount=${VM}/mount virtiofsd --fd 3 --shared-dir ${VM}/fs diff --git a/host/rootfs/image/usr/bin/create-vm-dependencies b/host/rootfs/image/usr/bin/create-vm-dependencies index f3a1b69..8fb9f3a 100755 --- a/host/rootfs/image/usr/bin/create-vm-dependencies +++ b/host/rootfs/image/usr/bin/create-vm-dependencies @@ -1,11 +1,29 @@ #!/bin/execlineb -S1 # SPDX-License-Identifier: EUPL-1.2+ -# SPDX-FileCopyrightText: 2024 Alyssa Ross +# SPDX-FileCopyrightText: 2024-2025 Alyssa Ross -if { mount -m --rbind -o nofail /run/vm/by-id/${1}/config/fs /run/vm/by-id/${1}/fs/config } +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/doc } -if { mount --rbind /run/vm/by-id/${1}/doc-run/doc /run/vm/by-id/${1}/fs/doc } +if { + unshare --propagation=slave --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 + } + + if { mount --make-shared --rbind /run/vm/by-id/${1} /run/vm/by-id/${1} } + + # The VM should not be able to write directly into a tmpfs, and the host + # should be able to assume there are no untrusted symlinks there, but there + # can be writable block-based bind mounted subdirectories. + if { mount --rbind -o nofail /run/vm/by-id/${1}/config/fs /run/vm/by-id/${1}/fs/config } + if { mount --rbind -o ro /run/vm/by-id/${1}/fs /run/vm/by-id/${1}/fs } + mount --rbind /run/vm/by-id/${1}/doc-run/doc /run/vm/by-id/${1}/fs/doc +} if { s6-instance-create /run/service/vm-services $1 } elglob -0 services /run/service/vm-services/instance/${1}/services/* diff --git a/host/rootfs/image/usr/bin/run-appimage b/host/rootfs/image/usr/bin/run-appimage index 6ccc61f..f2fe7bc 100755 --- a/host/rootfs/image/usr/bin/run-appimage +++ b/host/rootfs/image/usr/bin/run-appimage @@ -1,14 +1,12 @@ #!/bin/execlineb -S1 # SPDX-License-Identifier: EUPL-1.2+ -# SPDX-FileCopyrightText: 2024 Alyssa Ross +# SPDX-FileCopyrightText: 2024-2025 Alyssa Ross backtick -E dir { mktemp -d /run/vm/by-id/XXXXXX } backtick -E id { basename -- $dir } if { mkdir -p /run/configs/${id}/fs } -if { redirfd -w 1 /run/configs/${id}/fs/type echo appimage } -if { touch /run/configs/${id}/fs/run } -if { mount --rbind $1 /run/configs/${id}/fs/run } + if { ln -s /usr/lib/spectrum/img/appvm/blk /usr/lib/spectrum/img/appvm/vmlinux /run/configs/${id} @@ -18,6 +16,14 @@ if { ln -s /run/configs/${id} ${dir}/config } if { create-vm-dependencies $id } +if { + nsenter --mount=${dir}/mount + cd ${dir}/fs/config + if { redirfd -w 1 type echo appimage } + if { touch run } + mount --bind $1 run +} + piperw 4 3 background { fdclose 3 @@ -34,13 +40,6 @@ fdclose 3 if { s6-instance-delete /run/service/vm-services $id } -if { - forx -E mount { - /run/configs/${id}/fs/run - ${dir}/fs/config - ${dir}/fs/doc - } - umount $mount -} - +if { umount ${dir}/mount } # mount namespace +if { umount ${dir}/mount } # private bind mount 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 bf5b0b0..b1517a6 100755 --- a/host/rootfs/image/usr/bin/spectrum-update +++ b/host/rootfs/image/usr/bin/spectrum-update @@ -50,6 +50,9 @@ 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 + cd $1 + # If the directory is already mounted, unmount it. This prevents a # confusing error from mount. foreground { redirfd -w 2 /dev/null umount -- /run/vm/by-id/${update_vm_id}/fs/updates } -- 2.51.0