git: 5c12023beb94 - stable/15 - rc: Bail if /dev/null is not a device

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Mon, 08 Jun 2026 23:01:05 UTC
The branch stable/15 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c12023beb94609fb65845b76f21748a9f49bdca

commit 5c12023beb94609fb65845b76f21748a9f49bdca
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-06-05 15:53:29 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-06-08 23:00:43 +0000

    rc: Bail if /dev/null is not a device
    
    On startup, check that /dev/null exists and is a character device.
    Otherwise, one of two things will happen: either /dev is a writable
    directory and we will immediately create /dev/null as a regular file
    and dump garbage into it, or it does not and we will spit out a stream
    of error messages about failing to create /dev/null.
    
    PR:             295782
    MFC after:      1 week
    Reviewed by:    jhb, emaste
    Differential Revision:  https://reviews.freebsd.org/D57447
    
    (cherry picked from commit b5a96894f67a92f78f0641763eff1e0a46f2e036)
---
 libexec/rc/rc       |  5 +++++
 share/man/man8/rc.8 | 12 +++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libexec/rc/rc b/libexec/rc/rc
index db3c3e20ab44..75eef606b7fe 100644
--- a/libexec/rc/rc
+++ b/libexec/rc/rc
@@ -46,6 +46,11 @@ HOME=/
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 export HOME PATH
 
+if ! [ -c /dev/null ]; then
+	echo "/dev is not populated" >&2
+	exit 1
+fi
+
 if [ "$1" = autoboot ]; then
 	autoboot=yes
 	_boot="faststart"
diff --git a/share/man/man8/rc.8 b/share/man/man8/rc.8
index a68878f0a10a..bfdd65b52f4a 100644
--- a/share/man/man8/rc.8
+++ b/share/man/man8/rc.8
@@ -28,7 +28,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd September 20, 2024
+.Dd June 4, 2026
 .Dt RC 8
 .Os
 .Sh NAME
@@ -97,6 +97,16 @@ command provides a scripting interface to modify system config files.
 .Ss Operation of Nm
 .Bl -enum
 .It
+Verify that
+.Pa /dev/null
+exists and is a character device.
+If that is not the case,
+.Nm
+prints an error message and terminates.
+This is normally caused by forgetting to enable
+.Xr devfs 5
+in a jail's configuration.
+.It
 If autobooting, set
 .Va autoboot Ns = Ns Li yes
 and enable a flag