From 9e0363c7f908ab0434e2c7b164b5f75639af18bd Mon Sep 17 00:00:00 2001 From: Aymeric <198801145+grappig@users.noreply.github.com> Date: Thu, 1 Oct 2026 14:11:39 +0200 Subject: [PATCH 1/2] add proc mount point scaffold --- src/rootfs.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/rootfs.rs b/src/rootfs.rs index 7cf3fc4..54e2f1a 100644 --- a/src/rootfs.rs +++ b/src/rootfs.rs @@ -44,6 +44,22 @@ pub fn inspect(path: &Path) -> io::Result { }) } +pub fn proc_mount_point(path: &Path) -> io::Result { + let mount_point = path.join("proc"); + + if mount_point.is_dir() { + return Ok(mount_point); + } + + Err(io::Error::new( + io::ErrorKind::NotFound, + format!( + "rootfs proc directory does not exist: {}", + mount_point.display() + ), + )) +} + #[cfg(test)] mod tests { use super::{DIRECTORIES, initialize, inspect}; @@ -107,4 +123,16 @@ mod tests { assert!(inspect(&directory.0).is_err()); } + + #[test] + fn returns_the_proc_directory_as_a_mount_point() { + let directory = TestDirectory::new("test-rootfs-proc"); + + initialize(&directory.0).unwrap(); + + assert_eq!( + super::proc_mount_point(&directory.0).unwrap(), + directory.0.join("proc") + ); + } } From d7d23d27fecf319cf4a5e52cdf1462361fbf2ee1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 1 Oct 2026 12:17:02 +0000 Subject: [PATCH 2/2] Reject symlinked proc mount points Co-authored-by: grappig <198801145+grappig@users.noreply.github.com> --- src/rootfs.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/rootfs.rs b/src/rootfs.rs index 54e2f1a..e680ef7 100644 --- a/src/rootfs.rs +++ b/src/rootfs.rs @@ -47,7 +47,7 @@ pub fn inspect(path: &Path) -> io::Result { pub fn proc_mount_point(path: &Path) -> io::Result { let mount_point = path.join("proc"); - if mount_point.is_dir() { + if fs::symlink_metadata(&mount_point).is_ok_and(|metadata| metadata.file_type().is_dir()) { return Ok(mount_point); } @@ -62,7 +62,7 @@ pub fn proc_mount_point(path: &Path) -> io::Result { #[cfg(test)] mod tests { - use super::{DIRECTORIES, initialize, inspect}; + use super::{DIRECTORIES, initialize, inspect, proc_mount_point}; use std::{ fs, path::{Path, PathBuf}, @@ -131,8 +131,25 @@ mod tests { initialize(&directory.0).unwrap(); assert_eq!( - super::proc_mount_point(&directory.0).unwrap(), + proc_mount_point(&directory.0).unwrap(), directory.0.join("proc") ); } + + #[cfg(unix)] + #[test] + fn rejects_a_symlinked_proc_mount_point() { + use std::os::unix::fs::symlink; + + let directory = TestDirectory::new("test-rootfs-proc-symlink"); + let rootfs = directory.0.join("rootfs"); + let outside = directory.0.join("outside"); + + initialize(&rootfs).unwrap(); + fs::create_dir_all(&outside).unwrap(); + fs::remove_dir(rootfs.join("proc")).unwrap(); + symlink(&outside, rootfs.join("proc")).unwrap(); + + assert!(proc_mount_point(&rootfs).is_err()); + } }