Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio: PCI BAR mapping may be accessing invalid slots #1392

Open
cagatay-y opened this issue Sep 19, 2024 · 0 comments · May be fixed by #1403
Open

virtio: PCI BAR mapping may be accessing invalid slots #1392

cagatay-y opened this issue Sep 19, 2024 · 0 comments · May be fixed by #1403

Comments

@cagatay-y
Copy link
Contributor

According to the pci-types documentation, the EndpointHeader::bar function should not be called on slots that make up the second part of a 64-bit BAR. However, map_bar_mem calls the function (indirectly) for all slots in the maximum BAR count range, without checking if the previous BAR was 64-bits.

pub(crate) fn map_bar_mem(
device: &PciDevice<PciConfigRegion>,
) -> Result<Vec<VirtioPciBar>, PciError> {
let mapped_bars: Vec<VirtioPciBar> = (0..u8::try_from(MAX_BARS).unwrap())
.filter_map(|i| {
device
.memory_map_bar(i, true)
.map(|(addr, size)| (i, addr, size))
})

Additionally, it seems like the BARs are always 64-bit based on the lines below:

kernel/src/drivers/pci.rs

Lines 147 to 150 in 0245c53

if width != 64 {
warn!("Currently only mapping of 64 bit bars is supported!");
return None;
}

cagatay-y added a commit to cagatay-y/kernel that referenced this issue Sep 25, 2024
Currently, we map the BAR spaces ahead of time and then match them with the capability they belong to. We can get the slot index from the capability and map the space based on that instead. Although creating a BAR list independent of the capability list could be useful for devices that do not support capability lists, we assume the existence of that support anyways. Fixes hermit-os#1392.
cagatay-y added a commit to cagatay-y/kernel that referenced this issue Sep 25, 2024
Currently, we map the BAR spaces ahead of time and then match them with the capability they belong to. We can get the slot index from the capability and map the space based on that instead. Although creating a BAR list independent of the capability list could be useful for devices that do not support capability lists, we assume the existence of that support anyways. Fixes hermit-os#1392.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant