Repository navigation
Description
On KVM, restoring a snapshot whose saved XSAVE area is shorter than its legacy area and header (72 words), or whose header selects a component that ends past the area, panics the VM worker, in debug and release builds. A read never returns such an area, so only a crafted or corrupted snapshot file reaches this. MSHV and WHP pass the compact area to the hypervisor unchanged and are not affected.
Reproduction
restore_all a KVM VP saved state whose xsave element has 64 words (the legacy area only), or 72 words whose header's XCOMP_BV and XSTATE_BV both select AVX, on a host with AVX. Expected: the restore is refused. Actual: set_xsave panics, on an unwrap or on an out-of-range slice.
Cause
KvmVpStateAccess::set_xsave (vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs) converts the saved compact area with Xsave::write_standard (vmm_core/virt/src/x86/vp.rs). It unwraps the reads of the legacy area (in fxsave) and of the header, and slices both buffers at each component that the area's own header selects, without checking either bound:
// vmm_core/virt/src/x86/vp.rs
pub fn write_standard(&self, data: &mut [u8], caps: &X86PartitionCapabilities) {
// ...
for (i, feature) in caps.xsave.variable_features(header.xcomp_bv) {
// ...
if header.xstate_bv & (1 << i) != 0 {
data[offset..offset + len].copy_from_slice(&self.data.as_bytes()[cur..cur + len]);
}
// ...
fn xsave_header(&self) -> &XsaveHeader {
XsaveHeader::ref_from_prefix(&self.data.as_bytes()[XSAVE_LEGACY_LEN..])
.unwrap()Fix
fix.patch adds Xsave::fits_standard(len, caps), which holds exactly when write_standard can write the area into a buffer of len bytes: the area and the buffer hold the legacy area and the header, and each component that both header masks select lies within the area at its compact place and within the buffer at its standard offset. set_xsave checks it before it writes anything and returns KvmError::InvalidState otherwise, so such a restore fails with restore_all's StateError for the XSAVE element instead of panicking. Every area a read returns is accepted and written as before. The test fits_standard_is_what_write_standard_can_write (virt) covers three crafted areas, each bound exactly at its edge, components selected by only one of the two header masks, and 2000 random layouts, headers and lengths, and checks fits_standard against write_standard's own panics. The patch has no KVM-backed test.
Activity
tangruize commentedon Nov 8, 2026
Proposed patch
Patch against OpenVMM 3cf58a5234ed824435825c9f87187f5129219724. Save the contents below as
fix.patchand rungit apply fix.patch.fix.patchopenvmm: pin the XSAVE restore's bounds check