You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openvmm: 64-bit IOAPIC MMIO reads panic in IoApicDevice::mmio_read #1140
A guest's 64-bit MMIO read of the emulated IOAPIC can panic the VM worker, whether it reads INDEX at 0xfec00000 or DATA at 0xfec00010.
In vm/devices/chipset/src/ioapic/mod.rs, IoApicDevice::mmio_read clamps the source length to the 32-bit register size but copies into the complete destination:
let v = matchRegister(address &IOAPIC_DEVICE_MMIO_REGION_MASK){Register::INDEX => self.index.0.into(),Register::DATA => self.read_register(self.index),
_ => returnIoResult::Err(IoError::InvalidRegister),};// Allow any size read.let n = data.len().min(size_of_val(&v));
data.copy_from_slice(&v.to_ne_bytes()[..n]);IoResult::Ok
For an eight-byte access, n is four. copy_from_slice requires equal source and destination lengths, so copying the four-byte source into the eight-byte data slice panics. The register value itself does not need to be malformed.
Reproduction
In a VM exposing the emulated IOAPIC, issue a 64-bit load through a guest MMIO mapping of 0xfec00000 or 0xfec00010. The intercept receives an eight-byte destination and panics on the copy.
Fix
fix.patch copies the register bytes into data[..n] and zero-fills data[n..]. This preserves the intercept's arbitrary-width read contract: wider accesses return a zero-extended 32-bit register value, and 1–4 byte accesses retain their existing register bytes.
Patch against OpenVMM 998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below as fix.patch and run git apply fix.patch.
fix.patch
diff --git a/vm/devices/chipset/src/ioapic/mod.rs b/vm/devices/chipset/src/ioapic/mod.rs
index dc1eca62b..278ba4ce5 100644
--- a/vm/devices/chipset/src/ioapic/mod.rs+++ b/vm/devices/chipset/src/ioapic/mod.rs@@ -505,9 +505,12 @@ fn mmio_read(&mut self, address: u64, data: &mut [u8]) -> IoResult {
_ => return IoResult::Err(IoError::InvalidRegister),
};
- // Allow any size read.- let n = data.len().min(size_of_val(&v));- data.copy_from_slice(&v.to_ne_bytes()[..n]);+ // Allow any size read: the register's bytes, zero-extended past its+ // 32 bits.+ let bytes = v.to_ne_bytes();+ let n = data.len().min(bytes.len());+ data[..n].copy_from_slice(&bytes[..n]);+ data[n..].fill(0);
IoResult::Ok
}
@@ -596,4 +599,105 @@ fn masked_rte_emits_nothing() {
let rte = RedirectionEntry::new().with_masked(true).with_vector(0x30);
assert_eq!(rte.as_msi(), None);
}
++ /// An `IoApicRouting` that ignores every call.+ struct NullRouting;++ impl IoApicRouting for NullRouting {+ fn assert(&self, _irq: u8) {}++ fn set_route(&self, _irq: u8, _request: Option<(u64, u32)>) {}+ }++ fn ioapic() -> IoApicDevice {+ IoApicDevice::new(24, Box::new(NullRouting))+ }++ fn write_entry(dev: &mut IoApicDevice, n: u8, value: u64) {+ let base = IOAPIC_DEVICE_MMIO_REGION_BASE_ADDRESS;+ for (half, bits) in [(0u8, value as u32), (1, (value >> 32) as u32)] {+ dev.mmio_write(base, &[0x10 + 2 * n + half]).unwrap();+ dev.mmio_write(base + 0x10, &bits.to_ne_bytes()).unwrap();+ }+ }++ /// The registers the read tests read: (index, the data register's value after+ /// `program`): the ID (3), the version (0x11, 23 entries max), the arbitration+ /// ID, both halves of entry 5, an index past the last entry (0), an+ /// unsupported index (!0).+ fn register_cases() -> [(u8, u32); 7] {+ [+ (0x00, 3 << 24),+ (0x01, 0x0017_0011),+ (0x02, 0),+ (0x1a, 0x0001_a930),+ (0x1b, 0xc000_0000),+ (0x40, 0),+ (0x05, !0),+ ]+ }++ /// Sets the ID to 3 and entry 5 to a known value, then selects `index`.+ fn program(dev: &mut IoApicDevice, index: u8) {+ let base = IOAPIC_DEVICE_MMIO_REGION_BASE_ADDRESS;+ dev.mmio_write(base, &[0]).unwrap();+ dev.mmio_write(base + 0x10, &(3u32 << 24).to_ne_bytes())+ .unwrap();+ write_entry(dev, 5, 0xc000_0000_0001_a930);+ dev.mmio_write(base, &[index]).unwrap();+ }++ /// Regression test of BUG-05: a guest MMIO read of the IOAPIC wider than its+ /// 32-bit register returns the register zero-extended instead of panicking+ /// (`mmio_read` copied `min(len, 4)` bytes into the whole buffer with+ /// `copy_from_slice`, which panicked for an 8-byte read). For the index and+ /// the data register, reads of 5 to 8 bytes return the register's four bytes+ /// and zeros.+ #[test]+ fn wide_mmio_read_returns_the_register_zero_extended() {+ let base = IOAPIC_DEVICE_MMIO_REGION_BASE_ADDRESS;+ for (index, value) in register_cases() {+ for offset in [0u64, 0x10] {+ let mut dev = ioapic();+ program(&mut dev, index);+ let expected: u32 = if offset == 0 { index.into() } else { value };+ for len in 5..=8 {+ let mut data = vec![0xa5; len];+ dev.mmio_read(base + offset, &mut data).unwrap();+ assert_eq!(+ &data[..4],+ &expected.to_ne_bytes(),+ "{index:#x} {offset:#x} {len}"+ );+ assert!(+ data[4..].iter().all(|&b| b == 0),+ "{index:#x} {offset:#x} {len}"+ );+ }+ }+ }+ }++ /// BUG-05's fix keeps the narrow reads: a read of 1 to 4 bytes of the index or+ /// the data register returns exactly the first bytes of the 32-bit register.+ #[test]+ fn narrow_mmio_reads_return_the_register_bytes() {+ let base = IOAPIC_DEVICE_MMIO_REGION_BASE_ADDRESS;+ for (index, value) in register_cases() {+ for offset in [0u64, 0x10] {+ let mut dev = ioapic();+ program(&mut dev, index);+ let expected: u32 = if offset == 0 { index.into() } else { value };+ for len in 1..=4 {+ let mut data = vec![0xa5; len];+ dev.mmio_read(base + offset, &mut data).unwrap();+ assert_eq!(+ data,+ expected.to_ne_bytes()[..len],+ "{index:#x} {offset:#x} {len}"+ );+ }+ }+ }+ }
}
Activity
tangruize commentedon Nov 1, 2026
Proposed patch
Patch against OpenVMM
998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below asfix.patchand rungit apply fix.patch.fix.patchopenvmm: pin the IOAPIC's zero-extended wide reads