]> git.karo-electronics.de Git - karo-tx-linux.git/commit
vfio_pci: Test for extended capabilities if config space > 256 bytes
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Fri, 29 Apr 2016 04:11:52 +0000 (14:11 +1000)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 19 May 2016 21:04:40 +0000 (15:04 -0600)
commitf70552809419cd2abc0cc6469a07c9792a3aaa6c
tree90e6c16418c883f54310600686c5be2d210dd347
parent5ed4aba1265f3c7532bf4ae1f25a277568b86871
vfio_pci: Test for extended capabilities if config space > 256 bytes

PCI-Express spec says that reading 4 bytes at offset 100h should return
zero if there is no extended capability so VFIO reads this dword to
know if there are extended capabilities.

However it is not always possible to access the extended space so
generic PCI code in pci_cfg_space_size_ext() checks if
pci_read_config_dword() can read beyond 100h and if the check fails,
it sets the config space size to 100h.

VFIO does its own extended capabilities check by reading at offset 100h
which may produce 0xffffffff which VFIO treats as the extended config
space presense and calls vfio_ecap_init() which fails to parse
capabilities (which is expected) but right before the exit, it writes
zero at offset 100h which is beyond the buffer allocated for
vdev->vconfig (which is 256 bytes) which leads to random memory
corruption.

This makes VFIO only check for the extended capabilities if
the discovered config size is more than 256 bytes.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_config.c