]> www.infradead.org Git - users/jedix/linux-maple.git/commit
PCI: Check BAR index for validity
authorPhilipp Stanner <phasta@kernel.org>
Wed, 12 Mar 2025 08:06:35 +0000 (09:06 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 14 Mar 2025 15:35:12 +0000 (10:35 -0500)
commitb1a7f99967fc0c052db8e65b449c7b32b1e9177f
treec85e5106a47cd519f1426642878fdf3240185108
parentf09d3937d400433080d17982bd1a540da53a156d
PCI: Check BAR index for validity

Many functions in PCI use accessor macros such as pci_resource_len(),
which take a BAR index. That index, however, is never checked for
validity, potentially resulting in undefined behavior by overflowing the
array pci_dev.resource in the macro pci_resource_n().

Since many users of those macros directly assign the accessed value to
an unsigned integer, the macros cannot be changed easily anymore to
return -EINVAL for invalid indexes. Consequently, the problem has to be
mitigated in higher layers.

Add pci_bar_index_valid(). Use it where appropriate.

Link: https://lore.kernel.org/r/20250312080634.13731-4-phasta@kernel.org
Closes: https://lore.kernel.org/all/adb53b1f-29e1-3d14-0e61-351fd2d3ff0d@linux.intel.com/
Reported-by: Bingbu Cao <bingbu.cao@linux.intel.com>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
[kwilczynski: correct if-statement condition the pci_bar_index_is_valid()
helper function uses, tidy up code comments]
Signed-off-by: Krzysztof WilczyƄski <kwilczynski@kernel.org>
[bhelgaas: fix typo]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/devres.c
drivers/pci/iomap.c
drivers/pci/pci.c
drivers/pci/pci.h