File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,23 @@ impl Device {
5050 self . children . as_ref ( ) . map_or ( false , |v| !v. is_empty ( ) )
5151 }
5252
53+ // I know I can pretty this up, very much a wip
54+ pub ( crate ) fn is_mounted_in_pid_mounts ( & self , pid : rustix:: process:: Pid ) -> Result < bool > {
55+ let output = Command :: new ( "findmnt" )
56+ . arg ( "-N" )
57+ . arg ( ( pid. as_raw_nonzero ( ) ) . to_string ( ) )
58+ . arg ( "-S" )
59+ . arg ( self . path ( ) )
60+ . output ( )
61+ . expect ( "Failed to execute findmnt" ) ;
62+
63+ let mounts = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
64+
65+ let mounts_present = mounts. is_empty ( ) ;
66+
67+ Ok ( !mounts_present)
68+ }
69+
5370 // The "start" parameter was only added in a version of util-linux that's only
5471 // in Fedora 40 as of this writing.
5572 fn backfill_start ( & mut self ) -> Result < ( ) > {
Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ pub(crate) fn install_create_rootfs(
179179 ) ;
180180 }
181181
182+ // Always disallow writing to mounted device
183+ if device. is_mounted_in_pid_mounts ( rustix:: process:: getpid ( ) ) . expect ( "Failed to check mountpoints" ) {
184+ anyhow:: bail!( "Device {} is mounted" , device. path( ) )
185+ }
186+
182187 let run_bootc = Utf8Path :: new ( RUN_BOOTC ) ;
183188 let mntdir = run_bootc. join ( "mounts" ) ;
184189 if mntdir. exists ( ) {
You can’t perform that action at this time.
0 commit comments