Skip to content

Commit 9ab568b

Browse files
kalyazinShadowCurse
authored andcommitted
test(vmm): add regression test for virtio device write_config()
The test makes sure that a large offset value does not cause an overflow inside VirtioDevice::write_config(). Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent e07fa35 commit 9ab568b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ pub(crate) mod tests {
762762
// Make sure nothing got written.
763763
balloon.read_config(0, &mut actual_config_space);
764764
assert_eq!(actual_config_space, expected_config_space);
765+
766+
// Large offset that may cause an overflow.
767+
balloon.write_config(u64::MAX, &new_config_space);
768+
// Make sure nothing got written.
769+
balloon.read_config(0, &mut actual_config_space);
770+
assert_eq!(actual_config_space, expected_config_space);
765771
}
766772

767773
#[test]

src/vmm/src/devices/virtio/block/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ mod tests {
755755
// Make sure nothing got written.
756756
block.read_config(0, &mut actual_config_space);
757757
assert_eq!(actual_config_space, expected_config_space);
758+
759+
// Large offset that may cause an overflow.
760+
block.write_config(u64::MAX, &new_config_space);
761+
// Make sure nothing got written.
762+
block.read_config(0, &mut actual_config_space);
763+
assert_eq!(actual_config_space, expected_config_space);
758764
}
759765

760766
#[test]

src/vmm/src/devices/virtio/net/device.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,13 @@ pub mod tests {
998998
new_config_read = [0u8; MAC_ADDR_LEN];
999999
net.read_config(0, &mut new_config_read);
10001000
assert_eq!(new_config, new_config_read);
1001+
1002+
// Large offset that may cause an overflow.
1003+
net.write_config(u64::MAX, &new_config);
1004+
// Verify old config was untouched.
1005+
new_config_read = [0u8; MAC_ADDR_LEN];
1006+
net.read_config(0, &mut new_config_read);
1007+
assert_eq!(new_config, new_config_read);
10011008
}
10021009

10031010
#[test]

0 commit comments

Comments
 (0)