PCI: pci-bridge-emul: Fix array overruns, improve safety
authorRussell King <rmk+kernel@armlinux.org.uk>
Tue, 2 Feb 2021 17:07:46 +0000 (17:07 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 17 Feb 2021 23:25:31 +0000 (17:25 -0600)
commitf8ee579d53aca887d93f5f411462f25c085a5106
tree425c91abdb0bf4d44413f7d1635a6e72aebc2363
parent508d392ae0bb3729d4c18628e021968a1b11b32c
PCI: pci-bridge-emul: Fix array overruns, improve safety

We allow up to PCI_EXP_SLTSTA2 registers to be accessed, but the
pcie_cap_regs_behavior[] array only covers up to PCI_EXP_RTSTA.  Expand
this array to avoid walking off the end of it.

Do the same for pci_regs_behavior for consistency[], and add a
BUILD_BUG_ON() to also check the bridge->conf structure size.

Fixes: 23a5fba4d941 ("PCI: Introduce PCI bridge emulated config space common logic")
Link: https://lore.kernel.org/r/E1l6z9W-0006Re-MQ@rmk-PC.armlinux.org.uk
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Pali Rohár <pali@kernel.org>
drivers/pci/pci-bridge-emul.c