Skip to content

Commit 222e684

Browse files
Dan Carpenterawilliam
Dan Carpenter
authored andcommitted
vfio/pci: make an array larger
Smatch complains about a possible out of bounds error: drivers/vfio/pci/vfio_pci_config.c:1241 vfio_cap_init() error: buffer overflow 'pci_cap_length' 20 <= 20 The problem is that pci_cap_length[] was defined as large enough to hold "PCI_CAP_ID_AF + 1" elements. The code in vfio_cap_init() assumes it has PCI_CAP_ID_MAX + 1 elements. Originally, PCI_CAP_ID_AF and PCI_CAP_ID_MAX were the same but then we introduced PCI_CAP_ID_EA in commit f80b0ba ("PCI: Add Enhanced Allocation register entries") so now the array is too small. Let's fix this by making the array size PCI_CAP_ID_MAX + 1. And let's make a similar change to pci_ext_cap_length[] for consistency. Also both these arrays can be made const. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 033291e commit 222e684

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/vfio/pci/vfio_pci_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* 0: Removed from the user visible capability list
4747
* FF: Variable length
4848
*/
49-
static u8 pci_cap_length[] = {
49+
static const u8 pci_cap_length[PCI_CAP_ID_MAX + 1] = {
5050
[PCI_CAP_ID_BASIC] = PCI_STD_HEADER_SIZEOF, /* pci config header */
5151
[PCI_CAP_ID_PM] = PCI_PM_SIZEOF,
5252
[PCI_CAP_ID_AGP] = PCI_AGP_SIZEOF,
@@ -74,7 +74,7 @@ static u8 pci_cap_length[] = {
7474
* 0: Removed or masked from the user visible capabilty list
7575
* FF: Variable length
7676
*/
77-
static u16 pci_ext_cap_length[] = {
77+
static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = {
7878
[PCI_EXT_CAP_ID_ERR] = PCI_ERR_ROOT_COMMAND,
7979
[PCI_EXT_CAP_ID_VC] = 0xFF,
8080
[PCI_EXT_CAP_ID_DSN] = PCI_EXT_CAP_DSN_SIZEOF,

0 commit comments

Comments
 (0)