Skip to content

Commit c500a86

Browse files
Alexandra Diupinakwilczynski
authored andcommitted
PCI: kirin: Fix buffer overflow in kirin_pcie_parse_port()
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>
1 parent 8400291 commit c500a86

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
420420
"unable to get a valid reset gpio\n");
421421
}
422422

423-
pcie->num_slots++;
424-
if (pcie->num_slots > MAX_PCI_SLOTS) {
423+
if (pcie->num_slots + 1 >= MAX_PCI_SLOTS) {
425424
dev_err(dev, "Too many PCI slots!\n");
426425
return -EINVAL;
427426
}
427+
pcie->num_slots++;
428428

429429
ret = of_pci_get_devfn(child);
430430
if (ret < 0) {

0 commit comments

Comments
 (0)