Accept safe overlay work residue after unmount
This commit is contained in:
parent
e60baad993
commit
d38357a65d
2 changed files with 80 additions and 12 deletions
|
|
@ -34,10 +34,11 @@ use rustix::io::dup;
|
|||
use rustix::thread::{ThreadNameSpaceType, move_into_thread_name_spaces};
|
||||
use storage::{
|
||||
atomic_replace_at, create_directory, create_regular_file, descriptor_child_path,
|
||||
descriptor_path, directory_has_entries, host_path, inspect_directory, move_all_entries,
|
||||
move_selected_entries, open_directory, open_exact_directory_path, open_mounted_directory,
|
||||
open_or_create_quarantine, open_regular_file, path_from_host, remove_directory_contents,
|
||||
require_directory_descriptor_identity, require_same_descriptor, validate_relative_path,
|
||||
descriptor_path, host_path, inspect_directory, move_all_entries, move_selected_entries,
|
||||
open_directory, open_exact_directory_path, open_mounted_directory, open_or_create_quarantine,
|
||||
open_regular_file, path_from_host, remove_directory_contents,
|
||||
require_directory_descriptor_identity, require_maintenance_work_shape, require_same_descriptor,
|
||||
validate_relative_path,
|
||||
};
|
||||
|
||||
const MOUNT_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
|
@ -394,12 +395,7 @@ impl<'configuration> StateAnchorLayout<'configuration> {
|
|||
|
||||
fn require_maintenance_ready_allowing_quarantine(&self) -> Result<(), StateAnchorError> {
|
||||
self.require_unmounted()?;
|
||||
if directory_has_entries(&self.work_descriptor)? {
|
||||
return Err(StateAnchorError::InvalidLayout(
|
||||
"State Anchor work directory is not empty",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
require_maintenance_work_shape(&self.work_descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,14 @@ pub(super) fn remove_directory_contents(directory: impl AsFd) -> Result<(), Stat
|
|||
}
|
||||
|
||||
fn directory_names(directory: impl AsFd) -> Result<Vec<OsString>, StateAnchorError> {
|
||||
let descriptor = rustix::io::dup(directory.as_fd()).map_err(io::Error::from)?;
|
||||
let descriptor = openat2(
|
||||
directory.as_fd(),
|
||||
".",
|
||||
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC,
|
||||
Mode::empty(),
|
||||
confined_resolve_flags(),
|
||||
)
|
||||
.map_err(io::Error::from)?;
|
||||
let mut buffer = [std::mem::MaybeUninit::uninit(); 8192];
|
||||
let mut raw = RawDir::new(descriptor, &mut buffer);
|
||||
let mut names = Vec::new();
|
||||
|
|
@ -228,6 +235,31 @@ pub(super) fn directory_has_entries(directory: impl AsFd) -> Result<bool, StateA
|
|||
Ok(!directory_names(directory)?.is_empty())
|
||||
}
|
||||
|
||||
pub(super) fn require_maintenance_work_shape(directory: impl AsFd) -> Result<(), StateAnchorError> {
|
||||
let names = directory_names(&directory)?;
|
||||
if names.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
if names.as_slice() != [OsString::from("work")] {
|
||||
return Err(StateAnchorError::InvalidLayout(
|
||||
"State Anchor work directory has unsupported entries",
|
||||
));
|
||||
}
|
||||
let nested = open_directory(&directory, Path::new("work"))?;
|
||||
let parent = rustix::fs::fstat(&directory).map_err(io::Error::from)?;
|
||||
let child = rustix::fs::fstat(&nested).map_err(io::Error::from)?;
|
||||
if child.st_mode & 0o7777 != 0o700
|
||||
|| child.st_uid != parent.st_uid
|
||||
|| child.st_gid != parent.st_gid
|
||||
|| directory_has_entries(&nested)?
|
||||
{
|
||||
return Err(StateAnchorError::InvalidLayout(
|
||||
"State Anchor work directory has unsupported entries",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn validate_relative_path(path: &Path) -> Result<(), StateAnchorError> {
|
||||
if path.as_os_str().is_empty()
|
||||
|| path
|
||||
|
|
|
|||
Loading…
Reference in a new issue