mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-18 03:23:53 -04:00
virtio: pci: check bar values read from virtio config space
virtio pci config structures may in future have non-standard bar values in the bar field. We should anticipate this by skipping any structures containing such a reserved value. The bar value should never change: check for harmful modified values we re-read it from the config space in vp_modern_map_capability(). Also clean up an existing check to consistently use PCI_STD_NUM_BARS. Signed-off-by: Keir Fraser <keirf@google.com> Link: https://lore.kernel.org/r/20220323140727.3499235-1-keirf@google.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
committed by
Michael S. Tsirkin
parent
eb4cecb453
commit
3f63a1d7f6
@@ -35,6 +35,13 @@ vp_modern_map_capability(struct virtio_pci_modern_device *mdev, int off,
|
||||
pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, length),
|
||||
&length);
|
||||
|
||||
/* Check if the BAR may have changed since we requested the region. */
|
||||
if (bar >= PCI_STD_NUM_BARS || !(mdev->modern_bars & (1 << bar))) {
|
||||
dev_err(&dev->dev,
|
||||
"virtio_pci: bar unexpectedly changed to %u\n", bar);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (length <= start) {
|
||||
dev_err(&dev->dev,
|
||||
"virtio_pci: bad capability len %u (>%u expected)\n",
|
||||
@@ -120,7 +127,7 @@ static inline int virtio_pci_find_capability(struct pci_dev *dev, u8 cfg_type,
|
||||
&bar);
|
||||
|
||||
/* Ignore structures with reserved BAR values */
|
||||
if (bar > 0x5)
|
||||
if (bar >= PCI_STD_NUM_BARS)
|
||||
continue;
|
||||
|
||||
if (type == cfg_type) {
|
||||
|
||||
Reference in New Issue
Block a user