* [PATCH] PCI: kirin: Fix buffer overflow
@ 2024-07-12 8:43 Alexandra Diupina
2024-07-12 9:07 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 4+ messages in thread
From: Alexandra Diupina @ 2024-07-12 8:43 UTC (permalink / raw)
To: Xiaowei Song
Cc: Alexandra Diupina, Binghui Wang, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Mauro Carvalho Chehab, linux-pci, linux-kernel, lvc-project
In kirin_pcie_parse_port() pcie->num_slots is compared to
pcie->gpio_id_reset size (MAX_PCI_SLOTS). Need to fix
condition to pcie->num_slots >= MAX_PCI_SLOTS to
avoid out of bounds array access.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: b22dbbb24571 ("PCI: kirin: Support PERST# GPIOs for HiKey970 external PEX 8606 bridge")
Signed-off-by: Alexandra Diupina <adiupina@astralinux.ru>
---
drivers/pci/controller/dwc/pcie-kirin.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index d5523f302102..5ef3384c137d 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -413,7 +413,7 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
continue;
pcie->num_slots++;
- if (pcie->num_slots > MAX_PCI_SLOTS) {
+ if (pcie->num_slots >= MAX_PCI_SLOTS) {
dev_err(dev, "Too many PCI slots!\n");
ret = -EINVAL;
goto put_node;
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: kirin: Fix buffer overflow
2024-07-12 8:43 Alexandra Diupina
@ 2024-07-12 9:07 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2024-07-12 9:07 UTC (permalink / raw)
To: Alexandra Diupina
Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas, linux-pci,
linux-kernel, lvc-project
Em Fri, 12 Jul 2024 11:43:09 +0300
Alexandra Diupina <adiupina@astralinux.ru> escreveu:
> In kirin_pcie_parse_port() pcie->num_slots is compared to
> pcie->gpio_id_reset size (MAX_PCI_SLOTS). Need to fix
> condition to pcie->num_slots >= MAX_PCI_SLOTS to
> avoid out of bounds array access.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: b22dbbb24571 ("PCI: kirin: Support PERST# GPIOs for HiKey970 external PEX 8606 bridge")
> Signed-off-by: Alexandra Diupina <adiupina@astralinux.ru>
> ---
> drivers/pci/controller/dwc/pcie-kirin.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> index d5523f302102..5ef3384c137d 100644
> --- a/drivers/pci/controller/dwc/pcie-kirin.c
> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> @@ -413,7 +413,7 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
> continue;
>
> pcie->num_slots++;
> - if (pcie->num_slots > MAX_PCI_SLOTS) {
> + if (pcie->num_slots >= MAX_PCI_SLOTS) {
> dev_err(dev, "Too many PCI slots!\n");
> ret = -EINVAL;
> goto put_node;
Hmm... the logic will keep num_slots incremented when the error condition
is trigged. IMO, the code should be, instead:
if (pcie->num_slots + 1 >= MAX_PCI_SLOTS) {
dev_err(dev, "Too many PCI slots!\n");
ret = -EINVAL;
goto put_node;
}
pcie->num_slots++;
Thanks,
Mauro
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] PCI: kirin: Fix buffer overflow
@ 2024-09-03 11:58 Alexandra Diupina
2024-09-06 6:42 ` Krzysztof Wilczyński
0 siblings, 1 reply; 4+ messages in thread
From: Alexandra Diupina @ 2024-09-03 11:58 UTC (permalink / raw)
To: Xiaowei Song
Cc: Alexandra Diupina, Binghui Wang, Lorenzo Pieralisi,
Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
Mauro Carvalho Chehab, linux-pci, linux-kernel, lvc-project
In kirin_pcie_parse_port() pcie->num_slots is compared to
pcie->gpio_id_reset size (MAX_PCI_SLOTS). Need to fix
condition to pcie->num_slots + 1 >= MAX_PCI_SLOTS and move
pcie->num_slots increment lower to avoid out-of-bounds
array access.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: b22dbbb24571 ("PCI: kirin: Support PERST# GPIOs for HiKey970 external PEX 8606 bridge")
Signed-off-by: Alexandra Diupina <adiupina@astralinux.ru>
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
drivers/pci/controller/dwc/pcie-kirin.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index d5523f302102..deab1e653b9a 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -412,12 +412,12 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
if (pcie->gpio_id_reset[i] < 0)
continue;
- pcie->num_slots++;
- if (pcie->num_slots > MAX_PCI_SLOTS) {
+ if (pcie->num_slots + 1 >= MAX_PCI_SLOTS) {
dev_err(dev, "Too many PCI slots!\n");
ret = -EINVAL;
goto put_node;
}
+ pcie->num_slots++;
ret = of_pci_get_devfn(child);
if (ret < 0) {
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: kirin: Fix buffer overflow
2024-09-03 11:58 [PATCH] PCI: kirin: Fix buffer overflow Alexandra Diupina
@ 2024-09-06 6:42 ` Krzysztof Wilczyński
0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Wilczyński @ 2024-09-06 6:42 UTC (permalink / raw)
To: Alexandra Diupina
Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi, Rob Herring,
Bjorn Helgaas, Mauro Carvalho Chehab, linux-pci, linux-kernel,
lvc-project
Hello,
By the way, this would be v2, technically, but not to worry.
> In kirin_pcie_parse_port() pcie->num_slots is compared to
> pcie->gpio_id_reset size (MAX_PCI_SLOTS). Need to fix
> condition to pcie->num_slots + 1 >= MAX_PCI_SLOTS and move
> pcie->num_slots increment lower to avoid out-of-bounds
> array access.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
Applied to controller/kirin, thank you!
[1/1] PCI: kirin: Fix buffer overflow in kirin_pcie_parse_port()
https://git.kernel.org/pci/pci/c/c500a86693a1
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-06 6:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 11:58 [PATCH] PCI: kirin: Fix buffer overflow Alexandra Diupina
2024-09-06 6:42 ` Krzysztof Wilczyński
-- strict thread matches above, loose matches on Subject: below --
2024-07-12 8:43 Alexandra Diupina
2024-07-12 9:07 ` Mauro Carvalho Chehab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox