Skip to content

fix: reject attached Firecracker disks before host mutation - #631

Draft
hbrodin wants to merge 1 commit into
mainfrom
fix/issue-630-disk-ownership
Draft

hbrodin wants to merge 1 commit into
mainfrom
fix/issue-630-disk-ownership

Conversation

@hbrodin

@hbrodin hbrodin commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Partial hardening for #630.

Summary

  • Reject Firecracker host disk mutations when the currently named disk inode is mounted through a loop device or held open by a process. The privileged helper checks source and destination disks before copy, and checks before truncate, filesystem tools, format, mount, remove, and template publication.
  • Stop setup and commit when an old staging disk cannot be removed, preserving the existing published image.
  • Keep the claim scoped to the state observed during each host operation. The check does not establish VM lifetime ownership, serialize every helper operation, or identify a formerly named inode after a rename.

Verification

  • cargo test --workspace --locked --quiet — passed.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — passed.
  • cargo fmt -- --check and git diff --check — passed.
  • tests/privileged-disk.sh — passed on Linux with sudo and loop mounts, including mounted source/destination, foreign loop mount, and open process handle cases.
  • Firecracker VM integration — not run; no KVM host was available.
  • Lima VM integration — not run; the changed behavior is Linux only and no macOS/Lima host was available.

This remains a draft pending a representative Firecracker run and assessment of the hostwide process scan's availability cost. The broader design remains in #630, with implementation and recovery tracked by #633.

@hbrodin
hbrodin force-pushed the fix/issue-630-disk-ownership branch from e2cdb1f to 4922d24 Compare November 3, 2026 14:59
@hbrodin hbrodin changed the title fix: enforce managed disk ownership across VM lifecycle fix: reject attached Firecracker disks before host mutation Nov 3, 2026
Comment thread src/privileged_disk.rs
let descriptors = match fs::read_dir(entry.path().join("fd")) {
Ok(descriptors) => descriptors,
Err(error) if error.kind() == io::ErrorKind::NotFound => continue,
Err(error) => return Err(error).context("Cannot inspect process disk handles"),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unreadable fd directory for any unrelated process aborts every operation that checks a managed disk. The same applies to descriptor iteration and metadata below. This could make setup, new instance creation, commit, restore, disk resize, and instance destroy unavailable on hosts with restricted procfs or process-inspection policy. I did not reproduce such a restriction on the available host. Please keep the fail-closed check, but include the offending PID (and descriptor where applicable) and underlying error in the diagnostic, and exercise this path on a representative Firecracker host.

Comment thread src/privileged_disk.rs
Err(error) => return Err(error).context("Cannot inspect process disk handle"),
};
if held.dev() == identity.dev() && held.ino() == identity.ino() {
bail!("Managed disk is still open by process {pid}");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also rejects a benign read-only holder such as a backup or indexer. That is a reasonable safety tradeoff, but it can stop routine work until the reader exits. Could the error name the disk and give a concise way to inspect the PID and retry? The current message gives only a PID, so users may not know which host process to resolve.

Comment thread src/privileged_disk.rs
return Err(error).context("Cannot inspect loop backing identity");
}
if info.lo_device == identity.dev() && info.lo_inode == identity.ino() {
bail!("Managed disk is still attached to a host loop device");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an attachment is found, this message does not identify the loop device. Including its name would let the user inspect and unmount the specific attachment before retrying, without weakening the refusal.

@hbrodin

hbrodin commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

UX review of the current draft: I left three inline comments on process-scan failures and holder diagnostics. I found no confirmed broad regression on the available Linux host. A root-equivalent scan of about 146 processes and 1,022 descriptors took about 4 ms; copy, swap, and disk growth repeat the scan, so this should still be measured on a representative Firecracker host. Starting an existing instance does not take this new path; creating one does. Lima behavior is unchanged.

The unreadable-unrelated-process case is a conditional availability risk, not a reproduced failure here. Keeping the checks fail closed is appropriate. The requested changes are actionable error context and representative-host validation. Firecracker and Lima VM integration were not run for this PR head; the privileged disk probe and visible CI checks passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant