Skip to content

Harden VM-lifecycle + storage: false-success on cancel/failure paths (v1.121.14)#82

Merged
TheAbider merged 1 commit into
masterfrom
fix/vm-storage-hardening
Jul 1, 2026
Merged

Harden VM-lifecycle + storage: false-success on cancel/failure paths (v1.121.14)#82
TheAbider merged 1 commit into
masterfrom
fix/vm-storage-hardening

Conversation

@TheAbider

Copy link
Copy Markdown
Owner

Fixes from an adversarial audit of the VM export/import, offline-VHD, VHD conversion, batch S2D, and Hyper-V Replica modules. Recurring class: false success on a cancel/failure path (data-loss risk). 2 finder findings were refuted.

VM export false-success → source-VM data loss (53, HIGH)

If the operator stopped watching an export (ESC) or declined the 4-hour cap while vmms.exe was still exporting, the tool printed Export complete! and wrote a successful "Exported VM …" audit record — but Hyper-V was still writing a truncated, unbootable copy. Trusting the recorded success, an operator could decommission the source VM and lose it. It now checks $cancelRequested and reports the export as not confirmed.

Offline-VHD silent no-op (43, MED)

If the VHD's registry hive couldn't load (e.g. a leftover HKLM\OFFLINE_* mount from a prior crash), all offline settings were skipped yet it returned success — the VM booted with the sysprep-default name. It now returns $false when the SYSTEM hive didn't load (the computer name has no first-boot fallback) or when neither hive loaded.

VHD convert returns the wrong disk (41, MED)

If the final rename failed, Test-Path $finalPath was true (it's the un-converted dynamic copy), so the code reported that dynamic disk as "Fixed VHD" and orphaned the real fixed file. Success is now gated on the Move actually succeeding.

Hyper-V Replica (62)

  • Planned failover confirms prepared+shutdown (MED). A replica-side Complete-VMFailover is only lossless if the primary ran -Prepare and shut down first; without it you get silent data loss (unsynced delta) or split-brain. It now requires explicit confirmation.
  • Certificate-based replica works (LOW). It resolves + passes -CertificateThumbprint (the option always threw before). Dry-Run undos use -EA Stop so a failed rollback isn't a silent open-receiver no-op.

Batch S2D consent (50, LOW)

The AllowS2DDataLoss flag was dropped before the consent gate, making batch S2D enable permanently unreachable. It's now carried through.

Verification

  • New Section 201 (10 asserts). Structural 5357/5357; full Pester 312/312; PSSA 0. Monolithic rebuilt, parse check passed. Version → 1.121.14.

…(v1.121.14)

Fixes from an adversarial audit of the VM export/import, offline-VHD, VHD convert,
batch S2D, and Hyper-V Replica modules. Recurring class: false success on a
cancel/failure path (data-loss risk).

53-VMExportImport.ps1:
- A cancelled/timed-out VM export (operator stops watching or declines the 4h cap
  while vmms.exe is still exporting) is no longer reported 'Export complete!' and
  logged as a successful export. That false success could lead an operator to
  decommission the source VM against a truncated, unbootable export.

43-OfflineVHD.ps1:
- Offline customization returns $false (not success) when the SYSTEM hive didn't
  load, so the computer-name / offline settings that were silently skipped aren't
  reported as applied (the VM would otherwise boot with the sysprep-default name).

41-VHDManagement.ps1:
- dynamic->fixed conversion gates success on the Move actually succeeding, not on
  $finalPath still existing (which is the un-converted DYNAMIC copy) -- it no
  longer returns/reports the dynamic VHD as 'Fixed' and orphans the fixed file.

62-HyperVReplica.ps1:
- A replica-side planned failover now confirms the primary was prepared (-Prepare)
  and shut down before Complete-VMFailover (avoids silent data loss / split-brain).
- Certificate-based replica resolves + passes -CertificateThumbprint (the option
  never worked before). Dry-Run replica undos use -EA Stop (no silent open receiver).

50-EntryPoint.ps1:
- Batch S2D carries the AllowS2DDataLoss consent flag to the gate (was dropped,
  making batch S2D enable permanently unreachable).

Tests: Section 201 (10 asserts). Structural 5357/5357; Pester 312/312; PSSA 0.
Version stamps -> 1.121.14.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TheAbider TheAbider merged commit 1767601 into master Jul 1, 2026
7 checks passed
@TheAbider TheAbider deleted the fix/vm-storage-hardening branch July 1, 2026 16:11
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