Skip to content

Commit ed8e826

Browse files
committed
msix: relax assertion on data accesses from guest
It is true that writes/reads of an MSI-X table are either 32 or 64 bits long. However, we do check for this invariant in the `match` expression just after the assertion. If the invariant is not held (the guest tried to read/write with an invalid length) we just print an error and continue. This branch of the `match` block is never reached due to the assertion itself. To simplify things, just remove the assertion and let the `match` block logic handle invalid memory accesses. This should also help us better fuzz the bus accesses. Do add a check that the data access is up to 8 bytes long. These are all MMIO or Port IO accesses and they can't be bigger than 8 bytes. So this assertion should never fail in production (unless there's a KVM bug or we try to run Firecracker in some architecture that allows more than 64bit memory accesses). Signed-off-by: Babis Chalios <[email protected]>
1 parent dc4e6ca commit ed8e826

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/pci/src/msix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl MsixConfig {
219219
}
220220

221221
pub fn read_table(&self, offset: u64, data: &mut [u8]) {
222-
assert!((data.len() == 4 || data.len() == 8));
222+
assert!(data.len() <= 8);
223223

224224
let index: usize = (offset / MSIX_TABLE_ENTRIES_MODULO) as usize;
225225
let modulo_offset = offset % MSIX_TABLE_ENTRIES_MODULO;
@@ -272,7 +272,7 @@ impl MsixConfig {
272272
}
273273

274274
pub fn write_table(&mut self, offset: u64, data: &[u8]) {
275-
assert!((data.len() == 4 || data.len() == 8));
275+
assert!(data.len() <= 8);
276276

277277
let index: usize = (offset / MSIX_TABLE_ENTRIES_MODULO) as usize;
278278
let modulo_offset = offset % MSIX_TABLE_ENTRIES_MODULO;
@@ -368,7 +368,7 @@ impl MsixConfig {
368368
}
369369

370370
pub fn read_pba(&mut self, offset: u64, data: &mut [u8]) {
371-
assert!((data.len() == 4 || data.len() == 8));
371+
assert!(data.len() <= 8);
372372

373373
let index: usize = (offset / MSIX_PBA_ENTRIES_MODULO) as usize;
374374
let modulo_offset = offset % MSIX_PBA_ENTRIES_MODULO;

0 commit comments

Comments
 (0)