Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 95248d7

Browse files
Alexandra Diupinagregkh
Alexandra Diupina
authored andcommitted
PCI: kirin: Fix buffer overflow in kirin_pcie_parse_port()
[ Upstream commit c500a86 ] Within kirin_pcie_parse_port(), the pcie->num_slots is compared to pcie->gpio_id_reset size (MAX_PCI_SLOTS) which is correct and would lead to an overflow. Thus, fix condition to pcie->num_slots + 1 >= MAX_PCI_SLOTS and move pcie->num_slots increment below the if-statement to avoid out-of-bounds array access. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: b22dbbb ("PCI: kirin: Support PERST# GPIOs for HiKey970 external PEX 8606 bridge") Link: https://lore.kernel.org/linux-pci/20240903115823.30647-1-adiupina@astralinux.ru Signed-off-by: Alexandra Diupina <adiupina@astralinux.ru> [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d08754b commit 95248d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/pci/controller/dwc/pcie-kirin.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,12 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
415415
if (pcie->gpio_id_reset[i] < 0)
416416
continue;
417417

418-
pcie->num_slots++;
419-
if (pcie->num_slots > MAX_PCI_SLOTS) {
418+
if (pcie->num_slots + 1 >= MAX_PCI_SLOTS) {
420419
dev_err(dev, "Too many PCI slots!\n");
421420
ret = -EINVAL;
422421
goto put_node;
423422
}
423+
pcie->num_slots++;
424424

425425
ret = of_pci_get_devfn(child);
426426
if (ret < 0) {

0 commit comments

Comments
 (0)