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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 10:38:15 +0000 (11:38 +0100)
commitc2f17201d0e23110918ffac5ef220843e84cb2ff
tree2c4560c98c4dc34ff1925aa194119665e095affa
parentfc22917f48ee61eebfc462de92a685b9f508bddc
PCI: pci-bridge-emul: Fix array overruns, improve safety

[ Upstream commit f8ee579d53aca887d93f5f411462f25c085a5106 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pci/pci-bridge-emul.c