Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
3845941
Add experimental slot-owned MSHV servicing
bfjelds Nov 11, 2026
531184b
Support slot-owned MSHV during ACL first update
bfjelds Nov 11, 2026
d754cfc
Clean stale MSHV bootstrap files before checking capacity
bfjelds Nov 11, 2026
caef68e
Decode hypervisor validation failures in the preview client
bfjelds Nov 11, 2026
a0c777d
Document initial MSHV architecture support choice
bfjelds Nov 11, 2026
b3409b1
Discover initial MSHV mode from the installed ACL payload
bfjelds Nov 11, 2026
abc1207
Document offline MSHV initialization support limit
bfjelds Nov 11, 2026
1904245
Explain early MSHV mode-transition validation
bfjelds Nov 11, 2026
ee05d86
Document x64-only slot payload list
bfjelds Nov 11, 2026
3fe19a8
Document slot payload helper contracts
bfjelds Nov 11, 2026
b5a0107
Clarify read-only UKI removal selection helper
bfjelds Nov 11, 2026
8527cc5
Document new ESP validation and discovery functions
bfjelds Nov 11, 2026
87a453e
Explain provisioning-time MSHV validation
bfjelds Nov 11, 2026
38b83e1
Select validated update slot for conservative fallback commit
bfjelds Nov 11, 2026
5ca0440
Keep boot-validation context comment with its construction
bfjelds Nov 11, 2026
940971a
Explain commit mode validation and clean-install exemption
bfjelds Nov 11, 2026
1a7414a
Explain retained configuration during recovery validation
bfjelds Nov 11, 2026
541df4d
Simplify and explain hypervisor validation inputs
bfjelds Nov 11, 2026
4ea3e30
Separate health and hypervisor recovery match arms
bfjelds Nov 11, 2026
c2c6a48
Explain manual rollback mode-transition validation
bfjelds Nov 11, 2026
88e7b8b
Document MSHV boot and slot-owned servicing separately
bfjelds Nov 11, 2026
b5aa942
Link efitreeloader repository from MSHV documentation
bfjelds Nov 11, 2026
da5d234
Clarify MSHV disk streaming and recorded-mode restrictions
bfjelds Nov 11, 2026
fbc81f0
Remove disk streaming from MSHV limitations
bfjelds Nov 11, 2026
d0df622
Simplify MSHV identity-validation limitation wording
bfjelds Nov 11, 2026
452cf2f
Define successful MSHV identity validation against active slot
bfjelds Nov 11, 2026
fe30460
Make MSHV configuration test architecture-aware
bfjelds Nov 11, 2026
dd280ab
Move shared MSHV bundle helpers into boot module
bfjelds Nov 12, 2026
7026c0b
Clarify MSHV servicing function and block comments
bfjelds Nov 12, 2026
7acc0ed
Tighten MSHV comments and match enum style
bfjelds Nov 12, 2026
53e47d2
docs: clarify UEFI fallback selection matrix
bfjelds Nov 12, 2026
aa8a51d
docs: restore UEFI fallback lifecycle explanation
bfjelds Nov 12, 2026
e43d432
Move MSHV validation into ESP and use architecture helper
bfjelds Nov 12, 2026
3d0376d
Remove legacy MSHV payload preservation
bfjelds Nov 13, 2026
e82ca71
docs: remove experimental label from MSHV parameter
bfjelds Nov 13, 2026
f4d698e
Reclaim interrupted UKI staging before ESP deployment
bfjelds Nov 13, 2026
327f8e1
Detect MSHV images from COSI bootloader metadata
bfjelds Nov 13, 2026
c82c8d6
Align MSHV detection with upstream COSI metadata
bfjelds Nov 13, 2026
3fc019c
Use shared bootloader model for MSHV detection
bfjelds Nov 13, 2026
a63f54a
Share MSHV payload paths and correct servicing comments
bfjelds Nov 14, 2026
ce4bd43
Align MSHV imports with module conventions
bfjelds Nov 14, 2026
4404387
Discover image-specific MSHV secondary payloads
bfjelds Nov 14, 2026
a9a4140
Restore detailed servicing comments
bfjelds Nov 14, 2026
a31dd26
Fix MSHV fallback cleanup and deployment restrictions
bfjelds Nov 14, 2026
f0c172b
Generalize commit failure state and gate MSHV validation on runtime d…
bfjelds Nov 17, 2026
15179d9
Remove obsolete hypervisor failure state alias
bfjelds Nov 17, 2026
7abbc1c
Remove MSHV slot-staging capacity prediction
bfjelds Nov 17, 2026
a340334
Update cleanup documentation after preflight removal
bfjelds Nov 17, 2026
f255519
Gate UKI staging cleanup independently of MSHV
bfjelds Nov 17, 2026
dd3faf5
Ignore unrelated second-stage EFI files
bfjelds Nov 16, 2026
1f6840d
Allow MSHV fallback over ordinary GRUB files
bfjelds Nov 16, 2026
8c56b2c
Use MSHV boot component terminology
bfjelds Nov 17, 2026
7de7c0a
Consolidate commit success reporting
bfjelds Nov 17, 2026
539aae8
Separate bootloader staging from installed boot-tree copying
bfjelds Nov 17, 2026
7cf1706
Document boot-tree copying and replacement invariants
bfjelds Nov 17, 2026
cb2cf4c
Remove redundant ESP boot-file replacement wrapper
bfjelds Nov 17, 2026
e3e0131
boot: rely on staged copies instead of capacity estimates
bfjelds Nov 17, 2026
3da29ed
boot: explain image staging path handling
bfjelds Nov 17, 2026
c499dd0
boot: name tree-copy helpers for bootstrap and fallback
bfjelds Nov 17, 2026
f22eb3d
boot: explain preparation before slot cleanup
bfjelds Nov 17, 2026
f60748c
boot: document staging selection and MSHV validation
bfjelds Nov 17, 2026
016dc4a
boot: separate capability-specific file discovery
bfjelds Nov 17, 2026
ad8f36f
boot: document pre-staging UKI cleanup selection
bfjelds Nov 17, 2026
3419d0e
boot: show example capability-specific filepaths
bfjelds Nov 17, 2026
654aa0d
boot: document staging preparation contract
bfjelds Nov 17, 2026
d39df6a
boot: clarify MSHV bootstrap validation scope
bfjelds Nov 17, 2026
9366de6
boot: document runtime MSHV validation semantics
bfjelds Nov 17, 2026
631c89d
boot: remove MSHV-specific initialization validation
bfjelds Nov 17, 2026
fbbe51a
boot: rename file helpers to boot_tree
bfjelds Nov 17, 2026
da1499e
docs: clarify MSHV validation and failure boundaries
bfjelds Nov 17, 2026
4cfbf08
docs: scope MSHV explanation to its bootloader type
bfjelds Nov 17, 2026
77bf521
docs: remove MSHV boot-chain qualifier
bfjelds Nov 17, 2026
d555938
Document pre-refresh fallback health-check coverage
bfjelds Nov 18, 2026
2889c5a
Simplify MSHV servicing after review
bfjelds Nov 18, 2026
fe25cd0
Address ESP ownership and staging review feedback
bfjelds Nov 18, 2026
a624a70
Use walkdir for boot-tree traversal
bfjelds Nov 18, 2026
9ff608d
Move reusable boot-tree filesystem mechanics into osutils
bfjelds Nov 18, 2026
5cf1fe3
Clarify filesystem helper names and remove comment-only changes
bfjelds Nov 18, 2026
d3bc06a
Clarify MSHV validation function contracts
bfjelds Nov 18, 2026
f1de574
Clarify missing-path canonicalization helper
bfjelds Nov 18, 2026
2dc65fe
Address MSHV servicing review suggestions
bfjelds Nov 18, 2026
7aec517
Apply ESP visibility and error-reporting feedback
bfjelds Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ tracing-journald = "0.3.0"
tracing-subscriber = { version = "0.3.19", features = ["json"] }
url = { version = "2.5.4", features = ["serde"] }
uuid = { version = "1.11.0", features = ["serde", "v4"] }
walkdir = "2.5.0"
which = "6.0.3"
xattr = "1.3.1"
zstd = "0.13.3"
1 change: 1 addition & 0 deletions crates/osutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sys-mount = {workspace = true}
tempfile = {workspace = true}
thiserror = {workspace = true}
uuid = {workspace = true}
walkdir = {workspace = true}
which = {workspace = true}
xattr = {workspace = true}
regex = {workspace = true}
Expand Down
189 changes: 187 additions & 2 deletions crates/osutils/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use std::{
linux::fs::MetadataExt,
unix::fs::{MetadataExt as UnixMetadataExt, PermissionsExt},
},
path::{Path, PathBuf},
path::{self, Path, PathBuf},
};

use anyhow::{anyhow, bail, Context, Error};
use anyhow::{anyhow, bail, ensure, Context, Error};
use nix::unistd::{self, Gid, Uid};
use tempfile::NamedTempFile;
use walkdir::WalkDir;

/// Creates a file and all parent directories if they don't exist
pub fn create_file<S>(path: S) -> Result<File, Error>
Expand Down Expand Up @@ -198,6 +199,93 @@ where
})
}

/// Canonicalizes the longest existing prefix, then appends any missing components.
///
/// Resolves symlinks in the existing prefix without requiring the full path to
/// exist. Errors other than "not found" are propagated.
fn canonicalize_allow_missing(path: &Path) -> Result<PathBuf, Error> {
match fs::canonicalize(path) {
Ok(path) => Ok(path),
Err(error) if error.kind() == ErrorKind::NotFound => Ok(canonicalize_allow_missing(
path.parent().context("Missing path parent")?,
)?
.join(path.file_name().context("Missing path name")?)),
Err(error) => Err(error.into()),
}
}

/// Rejects equal paths or either path containing the other.
/// Resolves existing ancestors, including links, even when a suffix does not exist yet.
pub fn ensure_disjoint_paths(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<(), Error> {
let from = canonicalize_allow_missing(&path::absolute(from)?)?;
let to = canonicalize_allow_missing(&path::absolute(to)?)?;
ensure!(
!from.starts_with(&to) && !to.starts_with(&from),
"Source and destination paths overlap"
);
Ok(())
}

/// Copies a regular file or directory tree, preserving empty directories.
///
/// Rejects overlapping paths, source links and special files. Callers must ensure
/// that the destination tree and its ancestors contain no symlinks, and that no
/// destination file is a hard link to a source file. These conditions are not
/// checked: destination symlinks are followed, and hard-linked aliases can truncate
/// source files. Extra destination entries are retained; errors can leave a partial
/// copy, so callers needing preflight validation must perform it separately.
pub fn copy_recursively(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<(), Error> {
let from = from.as_ref();
let to = to.as_ref();
ensure_disjoint_paths(from, to)?;
for entry in WalkDir::new(from)
.follow_links(false)
.follow_root_links(false)
{
let entry = entry?;
let destination = if entry.depth() == 0 {
to.to_path_buf()
} else {
to.join(entry.path().strip_prefix(from)?)
};
if entry.file_type().is_dir() {
fs::create_dir_all(&destination).with_context(|| {
format!(
"Failed to create destination directory: {}",
destination.display()
)
})?;
} else {
ensure!(
entry.file_type().is_file(),
"Not a regular file: {}",
entry.path().display()
);
fs::copy(entry.path(), &destination).with_context(|| {
format!(
"Failed to copy '{}' to '{}'",
entry.path().display(),
destination.display()
)
})?;
}
}
Ok(())
}

/// Removes a file, link or directory tree without following a root link.
/// Missing entries are ignored.
pub fn remove_recursively_if_exists(path: impl AsRef<Path>) -> Result<(), Error> {
let path = path.as_ref();
match fs::symlink_metadata(path) {
Ok(metadata) if metadata.is_dir() => fs::remove_dir_all(path)?,
Ok(_) => fs::remove_file(path)?,
Err(error) if error.kind() == ErrorKind::NotFound => {}
Err(error) => return Err(error.into()),
}
Ok(())
}

/// Read the current process umask from `/proc/self/status` (thread-safe).
fn read_umask() -> Result<u32, Error> {
let status =
Expand Down Expand Up @@ -332,8 +420,105 @@ fn atomic_write_file_inner(
mod tests {
use super::*;

use std::os::unix::fs as unix_fs;

use nix::sys::stat::Mode;
use tempfile::tempdir;

#[test]
fn test_copy_recursively_preserves_empty_directories_and_root_files() {
let temp = tempdir().unwrap();
let source = temp.path().join("source");
let destination = temp.path().join("destination");
fs::create_dir_all(source.join("nested/empty")).unwrap();
fs::write(source.join("nested/payload.new"), b"payload").unwrap();
fs::create_dir_all(&destination).unwrap();
fs::write(destination.join("retained"), b"retained").unwrap();
copy_recursively(&source, &destination).unwrap();
assert!(destination.join("nested/empty").is_dir());
assert_eq!(
fs::read(destination.join("nested/payload.new")).unwrap(),
b"payload"
);
assert_eq!(fs::read(destination.join("retained")).unwrap(), b"retained");
let file = temp.path().join("file");
copy_recursively(source.join("nested/payload.new"), &file).unwrap();
assert_eq!(fs::read(&file).unwrap(), b"payload");
copy_recursively(&source, source.join("child")).unwrap_err();
assert!(!source.join("child").exists());
}

#[test]
fn test_copy_recursively_reports_failed_file_paths() {
let temp = tempdir().unwrap();
let source = temp.path().join("source");
let destination = temp.path().join("destination");
fs::create_dir(&source).unwrap();
fs::create_dir_all(destination.join("payload")).unwrap();
fs::write(source.join("payload"), b"payload").unwrap();

let error = copy_recursively(&source, &destination).unwrap_err();
let message = error.to_string();
assert!(message.contains(source.join("payload").to_str().unwrap()));
assert!(message.contains(destination.join("payload").to_str().unwrap()));
assert_eq!(fs::read(source.join("payload")).unwrap(), b"payload");
assert!(destination.join("payload").is_dir());
}

#[test]
fn test_copy_recursively_rejects_source_links_and_special_files() {
let temp = tempdir().unwrap();
let outside = temp.path().join("outside");
fs::create_dir(&outside).unwrap();
fs::write(outside.join("payload"), b"outside").unwrap();
let file_link = temp.path().join("file-link");
let directory_link = temp.path().join("directory-link");
let fifo = temp.path().join("fifo");
unix_fs::symlink(outside.join("payload"), &file_link).unwrap();
unix_fs::symlink(&outside, &directory_link).unwrap();
unistd::mkfifo(&fifo, Mode::S_IRUSR).unwrap();
for source in [&file_link, &directory_link, &fifo] {
let destination = temp.path().join("destination");
copy_recursively(source, &destination).unwrap_err();
assert!(!destination.exists());
}
assert_eq!(fs::read(outside.join("payload")).unwrap(), b"outside");
}

#[test]
fn test_ensure_disjoint_paths_resolves_existing_ancestors() {
let temp = tempdir().unwrap();
let source = temp.path().join("source");
let alias = temp.path().join("alias");
fs::create_dir(&source).unwrap();
unix_fs::symlink(&source, &alias).unwrap();
ensure_disjoint_paths(&source, &alias).unwrap_err();
ensure_disjoint_paths(&source, alias.join("missing/child")).unwrap_err();
ensure_disjoint_paths(alias.join("missing/child"), &source).unwrap_err();
ensure_disjoint_paths(&source, temp.path().join("other/missing")).unwrap();
}

#[test]
fn test_remove_recursively_if_exists_preserves_link_targets() {
let temp = tempdir().unwrap();
let outside = temp.path().join("outside");
fs::create_dir(&outside).unwrap();
fs::write(outside.join("payload"), b"outside").unwrap();
let link = temp.path().join("link");
unix_fs::symlink(&outside, &link).unwrap();
remove_recursively_if_exists(&link).unwrap();
remove_recursively_if_exists(&link).unwrap();
assert!(!link.exists());
assert_eq!(fs::read(outside.join("payload")).unwrap(), b"outside");
let entry = temp.path().join("entry");
fs::create_dir_all(entry.join("nested")).unwrap();
fs::write(entry.join("nested/payload"), b"payload").unwrap();
remove_recursively_if_exists(&entry).unwrap();
fs::write(&entry, b"file").unwrap();
remove_recursively_if_exists(&entry).unwrap();
assert!(!entry.exists());
}

#[test]
fn test_create_file() {
let dir = tempdir().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions crates/osutils/src/osrelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pub fn is_azl3() -> Result<bool, Error> {
Ok(OsRelease::read()?.get_distro().is_azl3())
}

/// Returns whether the host is running the ACL image.
pub fn is_acl() -> Result<bool, Error> {
Ok(OsRelease::read()?.get_distro().is_acl())
}
Comment thread
bfjelds marked this conversation as resolved.
Resolved

/// Splits one os-release-style `KEY=VALUE` line into its key and
/// unquoted/trimmed value, or `None` for a blank, comment, or malformed
/// line. Shared by [`read_key`], [`OsRelease::parse`], and
Expand Down
5 changes: 4 additions & 1 deletion crates/sysdefs/src/acl.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! Azure Container Linux (ACL) system definitions.
//!
//! Fixed PARTUUIDs and partition type UUIDs for the ACL UKI disk layout,
//! ESP mount point, fixed PARTUUIDs and partition type UUIDs for the ACL UKI disk layout,
//! sourced from acl-scripts disk_layout_uki.json.

use uuid::{uuid, Uuid};

/// ACL EFI System Partition mount point.
pub const ACL_ESP_MOUNT_POINT: &str = "/boot";

/// ACL USR partition A PARTUUID.
pub const ACL_USR_A_PARTUUID: Uuid = uuid!("7130c94a-213a-4e5a-8e26-6cce9662f132");

Expand Down
5 changes: 5 additions & 0 deletions crates/sysdefs/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ impl SystemArchitecture {
SystemArchitecture::Aarch64
}
}

/// Returns whether this is the 64-bit x86 architecture.
pub const fn is_x64(&self) -> bool {
matches!(self, Self::Amd64)
}
}

impl<'de> Deserialize<'de> for SystemArchitecture {
Expand Down
1 change: 1 addition & 0 deletions crates/trident/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ tracing-journald = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }
walkdir = { workspace = true }
zstd = { workspace = true }

# gRPC API Dependencies
Expand Down
1 change: 1 addition & 0 deletions crates/trident/src/engine/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::engine::Subsystem;
use super::EngineContext;

pub(super) mod grub;
pub(crate) mod mshv;
pub mod uki;

pub(crate) const ESP_EXTRACTION_DIRECTORY: &str = VAR_TMP_PATH;
Expand Down
72 changes: 72 additions & 0 deletions crates/trident/src/engine/boot/mshv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//! Validates MSHV boot components independently of the surrounding bootloader chain.

use std::{fs, io::ErrorKind, path::Path};

use anyhow::{ensure, Context, Error};

use crate::subsystems::esp::boot_tree;

const MSHV_BOOT_FILES: &[&str] = &["HvLoader.efi", "lxhvloader.dll"];
const MSHV_BOOT_COMPONENTS_DIR: &str = "Windows";

/// Detects MSHV components in a slot or fallback BOOT directory.
///
/// Any loader filename or Windows entry triggers validation of both required
/// loaders and the optional Windows tree. Returns true only after validation;
/// partial components are an error, not an ordinary non-MSHV directory.
/// Returns false when no markers exist, including when the directory is absent.
/// Filesystem inspection errors propagate without modifying the directory.
pub(crate) fn has_slot_mshv_boot_components(boot_dir: &Path) -> Result<bool, Error> {
for marker in MSHV_BOOT_FILES
.iter()
.copied()
.chain([MSHV_BOOT_COMPONENTS_DIR])
{
match fs::symlink_metadata(boot_dir.join(marker)) {
Ok(_) => {
validate_boot_components(boot_dir)?;
return Ok(true);
}
Err(error) if error.kind() == ErrorKind::NotFound => {}
Err(error) => return Err(error).context("Failed to inspect MSHV boot components"),
}
}
Ok(false)
}

/// Requires regular HvLoader.efi and lxhvloader.dll files in `boot_dir`.
///
/// Windows is optional, but when present must be a directory tree containing
/// only regular files/directories, with no links or reserved replacement names.
/// Checks filesystem structure, not binary contents or runtime hypervisor identity.
/// Supporting bootloaders, including ETL's second stage, are validated separately.
/// This function does not modify the directory.
pub(crate) fn validate_boot_components(boot_dir: &Path) -> Result<(), Error> {
for name in MSHV_BOOT_FILES {
let path = boot_dir.join(name);
ensure!(
fs::symlink_metadata(&path)
.with_context(|| format!("Missing MSHV boot component: {name}"))?
.is_file(),
"Invalid MSHV boot component: {name}"
);
}
let windows = boot_dir.join(MSHV_BOOT_COMPONENTS_DIR);
match fs::symlink_metadata(&windows) {
Ok(_) => {
boot_tree::filepaths(&windows)?;
}
Err(error) if error.kind() == ErrorKind::NotFound => {}
Err(error) => return Err(error).context("Failed to inspect MSHV boot component directory"),
}
Ok(())
}

#[cfg(test)]
pub(crate) const MSHV_SLOT_BOOT_FILES: &[&str] = &[
"bootx64.efi",
"grubx64.efi",
"second.efi",
"HvLoader.efi",
"lxhvloader.dll",
];
Loading
Loading