Skip to content

Disallow MSR read/writes#991

Draft
ludfjig wants to merge 5 commits into
hyperlight-dev:mainfrom
ludfjig:reset2
Draft

Disallow MSR read/writes#991
ludfjig wants to merge 5 commits into
hyperlight-dev:mainfrom
ludfjig:reset2

Conversation

@ludfjig

@ludfjig ludfjig commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Disallows reading/writing MSRs in the guest. Can be bypassed with unsafe function on SandboxConfiguration. The goal is to prevent guest state to persist across snapshot-restores.

Will mark ready for review once KVM releases new version, which should include newly added KVM_X86_SET_MSR_FILTER vm ioctl that this PR depends on, see rust-vmm/kvm#359

@ludfjig ludfjig force-pushed the reset2 branch 7 times, most recently from aeca04d to 968f2f4 Compare October 31, 2025 00:29
@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Dec 2, 2025
@ludfjig ludfjig force-pushed the reset2 branch 3 times, most recently from e859ff9 to e793129 Compare December 8, 2025 18:42
@ludfjig ludfjig changed the title Reset more state when restoring snapshot Reset MSRs when restoring snapshot Dec 18, 2025
@ludfjig ludfjig changed the title Reset MSRs when restoring snapshot Disallow MSR read/writes Feb 10, 2026
@ludfjig ludfjig force-pushed the reset2 branch 5 times, most recently from 8f55249 to 3bb2294 Compare February 13, 2026 23:16
@ludfjig ludfjig force-pushed the reset2 branch 2 times, most recently from 032168d to c0383dd Compare February 18, 2026 19:27
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
ludfjig added 2 commits July 10, 2026 11:28
Design doc for resetting guest-written MSRs across MultiUseSandbox::restore() with a per-MSR opt-in allow list, plus a KVM Phase 1 implementation handoff brief.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Reset the guest-visible stateful MSRs on sandbox restore and gate the
per-MSR allow list behind validation, so guest MSR writes cannot leak
across restores. Adds host-index sweep, negative-leak, denied-MSR fault,
and partial-set poison tests, plus documentation of the reset-set
completeness argument and the dormant host_specific/TSC machinery.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Handoff for the mshv agent: the pass-through completeness gap, the Hyper-V/mshv source facts (SVM pass-through MSR set, intercept behavior) the agent cannot see, and the reset-or-mask plan per MSR class.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Widen the KVM-only MSR reset machinery to also cover the mshv backend, so
guest MSR writes do not leak across a snapshot restore on Hyper-V. Implement
capture_msrs/apply_msrs on MshvVm using batched get_msrs/set_msrs, detecting
failure from the returned error (set_msrs reports no count) and poisoning on
a partial apply.

mshv has no per-MSR deny filter, so a guest can write architectural
pass-through MSRs with no intercept, and completeness rests on reset. The
reset set covers every stateful pass-through MSR the crate can map and
restore: the core syscall, sysenter, and base MSRs, KERNEL_GS_BASE,
SPEC_CTRL, and the CET MSRs where CET is active. mshv has no host-probed
index list, so the reset set is resolved by probing each mappable index
with a get at init, including only those that read back. That resets CET on
hosts where it is exposed and skips it elsewhere without failing init. The
allow list is validated at VM creation so a non-resettable or unmappable
request is a hard error.

The pass-through classes with no mapping (PMU, AMX/XFD, FRED, arch LBR)
cannot be reset. Completeness holds because the minimal partition enables
none of them, so a guest access faults. A test asserts this on the host.

Add mshv tests: a pass-through MSR write is reset across restore, a guest
read of an unresettable class faults, a rejected set_msrs during restore
poisons the sandbox, an allowed MSR does not leak across restore, and
allowing a non-resettable or unmapped MSR fails sandbox creation.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant