Skip to content

Commit

Permalink
virtio: fix potential out of bounds of array access
Browse files Browse the repository at this point in the history
Signed-off-by: Jiaqi Gao <[email protected]>
  • Loading branch information
gaojiaqi7 committed May 6, 2024
1 parent 986bd71 commit f6ac667
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/devices/virtio/src/virtio_pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ use crate::mem;
use crate::{Result, VirtioError, VirtioTransport};
use pci::PciDevice;

const VIRTIO_PCI_MAX_CAP_TYPE: usize = 6;

#[allow(clippy::enum_variant_names)]
enum VirtioPciCapabilityType {
CommonConfig = 1,
Expand All @@ -75,13 +77,13 @@ enum VirtioPciCapabilityType {

#[derive(Default)]
struct CheckRegionOverlap {
flag: [bool; 6], // VirtioPciCapabilityType max value
interval: [[u64; 2]; 6], // VirtioPciCapabilityType max value
flag: [bool; VIRTIO_PCI_MAX_CAP_TYPE], // VirtioPciCapabilityType max value
interval: [[u64; 2]; VIRTIO_PCI_MAX_CAP_TYPE], // VirtioPciCapabilityType max value
}

impl CheckRegionOverlap {
fn set_region(&mut self, index: usize, base: u64, length: u64) -> Result<()> {
if index > 6 {
if index >= VIRTIO_PCI_MAX_CAP_TYPE {
return Err(VirtioError::InvalidParameter);
}

Expand Down

0 comments on commit f6ac667

Please sign in to comment.