patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Spectrum OS Development <devel@spectrum-os.org>
Cc: Alyssa Ross <hi@alyssa.is>, Demi Marie Obenour <demiobenour@gmail.com>
Subject: [PATCH v2] Add /dev/fd and /dev/std*
Date: Thu, 18 Sep 2025 15:45:01 -0400	[thread overview]
Message-ID: <20250918-util-linux-switch-root-v2-1-762ac91ea24b@gmail.com> (raw)
In-Reply-To: <20250914-util-linux-switch-root-v1-0-9cf9349cbca3@gmail.com>

This is nearly same as 14483e1a690c (img/app: add /dev/fd and /dev/std*),
but for the host and for vm/sys/net.  The only difference is that the
symlinks are created in init, rather than in rc.init.  This ensures that
nothing in the main system can run before they the links are created.

While only Spectrum-provided code should run in these VMs, third-party
dependencies are likely to only be tested in an environment where these
links are present.  Since the BSDs also have these links, some code
might even use them on purpose.

Not having these links could cause severe bugs.  For instance, if
/dev/stdout or /dev/stderr is missing, writing to them will create a
regular file instead.  This could cause other code to misbehave.
Furthermore, /dev is a devtmpfs, so this could consume a lot of memory.

[1]: https://spectrum-os.org/lists/archives/spectrum-devel/87h5xdjo9p.fsf@alyssa.is/

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
Changes in v2:
- Do not switch to util-linux switch_root as Busybox switch_root is
  good enough.
- Leave /proc and /sys in /etc/fstab as they will not be remounted if
  already mounted.
- Link to v1: https://spectrum-os.org/lists/archives/spectrum-devel/20250914-util-linux-switch-root-v1-0-9cf9349cbca3@gmail.com
---
 host/rootfs/image/etc/s6-linux-init/scripts/rc.init | 5 +++++
 vm/sys/net/image/etc/s6-linux-init/scripts/rc.init  | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/host/rootfs/image/etc/s6-linux-init/scripts/rc.init b/host/rootfs/image/etc/s6-linux-init/scripts/rc.init
index 674fd38cc76837c7be25a5ef060f0f4d4b786394..46e5cd6d1b99c12fab84a2797b37d9f4eccaa56a 100755
--- a/host/rootfs/image/etc/s6-linux-init/scripts/rc.init
+++ b/host/rootfs/image/etc/s6-linux-init/scripts/rc.init
@@ -4,6 +4,11 @@
 
 if { s6-rc-init -c /etc/s6-rc /run/service }
 
+if { ln -s /proc/self/fd /dev }
+if { ln -s /proc/self/fd/0 /dev/stdin }
+if { ln -s /proc/self/fd/1 /dev/stdout }
+if { ln -s /proc/self/fd/2 /dev/stderr }
+
 if { mount --make-shared /run }
 if { mount -a --mkdir }
 
diff --git a/vm/sys/net/image/etc/s6-linux-init/scripts/rc.init b/vm/sys/net/image/etc/s6-linux-init/scripts/rc.init
index 1016d0c62bc6103bc9e865a389f5d482ef6c2b76..4378400b0b34f12bfa6a994029546f9c38058d10 100755
--- a/vm/sys/net/image/etc/s6-linux-init/scripts/rc.init
+++ b/vm/sys/net/image/etc/s6-linux-init/scripts/rc.init
@@ -4,6 +4,11 @@
 
 if { s6-rc-init -c /etc/s6-rc /run/service }
 
+if { ln -s /proc/self/fd /dev }
+if { ln -s /proc/self/fd/0 /dev/stdin }
+if { ln -s /proc/self/fd/1 /dev/stdout }
+if { ln -s /proc/self/fd/2 /dev/stderr }
+
 if { mkdir -p /dev/pts /dev/shm }
 if { mount -a }
 

---
base-commit: edd53bb5dd9b682fec744d6df7921b64e0f56565
change-id: 20250914-util-linux-switch-root-10034b149e45
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)


  parent reply	other threads:[~2025-09-18 19:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15  0:18 [PATCH 0/3] Minor improvements to the Spectrum OS boot process Demi Marie Obenour
2025-09-15  0:18 ` [PATCH 1/3] host/initramfs: Use util-linux switch_root Demi Marie Obenour
2025-09-17 11:44   ` Alyssa Ross
2025-09-18  2:39     ` Demi Marie Obenour
2025-09-19  9:12       ` Alyssa Ross
2025-09-18 19:41     ` Demi Marie Obenour
2025-09-15  0:18 ` [PATCH 2/3] Add /dev/fd and /dev/std* Demi Marie Obenour
2025-09-17 11:29   ` Alyssa Ross
2025-09-15  0:19 ` [PATCH 3/3] host/rootfs: Avoid redundant mounts of /proc and /sys Demi Marie Obenour
2025-09-17 11:31   ` Alyssa Ross
2025-09-18  2:42     ` Demi Marie Obenour
2025-09-19  9:16       ` Alyssa Ross
2025-09-18 19:45 ` Demi Marie Obenour [this message]
2025-09-19  9:29   ` [PATCH v2] Add /dev/fd and /dev/std* Alyssa Ross

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=20250918-util-linux-switch-root-v2-1-762ac91ea24b@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=hi@alyssa.is \
    /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).