patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Subject: [PATCH 2/2] host/rootfs: prevent VM ID reuse
Date: Wed, 10 Dec 2025 11:55:15 +0100	[thread overview]
Message-ID: <20251210105515.1033548-2-hi@alyssa.is> (raw)
In-Reply-To: <20251210105515.1033548-1-hi@alyssa.is>

Since lsvm ignores empty directories, we can just leave them around to
prevent mktemp -d from reusing the name.

Fixes: b51a97f ("host/rootfs: add run-appimage program")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
 host/rootfs/image/usr/bin/run-appimage | 7 ++++---
 host/rootfs/image/usr/bin/run-flatpak  | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/host/rootfs/image/usr/bin/run-appimage b/host/rootfs/image/usr/bin/run-appimage
index d61a79c6..27c6e093 100755
--- a/host/rootfs/image/usr/bin/run-appimage
+++ b/host/rootfs/image/usr/bin/run-appimage
@@ -44,8 +44,9 @@ if { s6-instance-delete /run/service/vm-services $id }
 if { umount ${dir}/mount } # mount namespace
 if { umount ${dir}/mount } # private bind mount
 
-# Atomically swap the VM directory with an empty one, which will be ignored by
-# lsvm, then remove it, so we never have half a VM directory.
+# Atomically replace the VM directory with an empty one,
+# which will keep holding the ID so it's not reused,
+# but be ignored by lsvm.
 if { mkdir /run/vm/by-id/.${id} }
 if { exch /run/vm/by-id/.${id} $dir }
-background { rm -rf /run/vm/by-id/.${id} $dir }
+background { rm -rf /run/vm/by-id/.${id} }
diff --git a/host/rootfs/image/usr/bin/run-flatpak b/host/rootfs/image/usr/bin/run-flatpak
index 6be21075..0cb236f4 100755
--- a/host/rootfs/image/usr/bin/run-flatpak
+++ b/host/rootfs/image/usr/bin/run-flatpak
@@ -46,8 +46,9 @@ if { s6-instance-delete -- /run/service/vm-services $id }
 if { umount ${dir}/mount } # mount namespace
 if { umount ${dir}/mount } # private bind mount
 
-# Atomically swap the VM directory with an empty one, which will be ignored by
-# lsvm, then remove it, so we never have half a VM directory.
+# Atomically replace the VM directory with an empty one,
+# which will keep holding the ID so it's not reused,
+# but be ignored by lsvm.
 if { mkdir /run/vm/by-id/.${id} }
 if { exch /run/vm/by-id/.${id} $dir }
-background { rm -rf /run/vm/by-id/.${id} $dir }
+background { rm -rf /run/vm/by-id/.${id} }
-- 
2.51.0


      reply	other threads:[~2025-12-10 10:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10 10:55 [PATCH 1/2] host/rootfs: atomically delete VM directories Alyssa Ross
2025-12-10 10:55 ` Alyssa Ross [this message]

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=20251210105515.1033548-2-hi@alyssa.is \
    --to=hi@alyssa.is \
    --cc=devel@spectrum-os.org \
    /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://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

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).