Skip to content

Commit 3781be5

Browse files
committed
install: Never traverse mount points with --wipe
If we encounter a mount point when attempting to wipe a filesystem, then something has definitely gone wrong. At the install phase we should only be operating on a single physical filesystem. Signed-off-by: Colin Walters <[email protected]>
1 parent a442ac2 commit 3781be5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/src/install.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use camino::Utf8Path;
2828
use camino::Utf8PathBuf;
2929
use cap_std::fs::{Dir, MetadataExt};
3030
use cap_std_ext::cap_std;
31+
use cap_std_ext::cap_std::fs::FileType;
3132
use cap_std_ext::cap_std::fs_utf8::DirEntry as DirEntryUtf8;
3233
use cap_std_ext::cap_tempfile::TempDir;
3334
use cap_std_ext::cmdext::CapStdExtCommandExt;
@@ -56,7 +57,7 @@ use crate::progress_jsonl::ProgressWriter;
5657
use crate::spec::ImageReference;
5758
use crate::store::Storage;
5859
use crate::task::Task;
59-
use crate::utils::sigpolicy_from_opts;
60+
use crate::utils::{open_dir_noxdev, sigpolicy_from_opts};
6061

6162
/// The toplevel boot directory
6263
const BOOT: &str = "boot";
@@ -1560,12 +1561,18 @@ fn require_empty_rootdir(rootfs_fd: &Dir) -> Result<()> {
15601561
/// Remove all entries in a directory, but do not traverse across distinct devices.
15611562
#[context("Removing entries (noxdev)")]
15621563
fn remove_all_in_dir_no_xdev(d: &Dir) -> Result<()> {
1563-
let parent_dev = d.dir_metadata()?.dev();
15641564
for entry in d.entries()? {
15651565
let entry = entry?;
1566-
let entry_dev = entry.metadata()?.dev();
1567-
if entry_dev == parent_dev {
1568-
d.remove_all_optional(entry.file_name())?;
1566+
let name = entry.file_name();
1567+
let etype = entry.file_type()?;
1568+
if etype == FileType::dir() {
1569+
if let Some(subdir) = open_dir_noxdev(d, &name)? {
1570+
remove_all_in_dir_no_xdev(&subdir)?;
1571+
} else {
1572+
anyhow::bail!("Found unexpected mount point {name:?}");
1573+
}
1574+
} else {
1575+
d.remove_file_optional(&name)?;
15691576
}
15701577
}
15711578
anyhow::Ok(())

0 commit comments

Comments
 (0)