public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Alexandra Diupina <adiupina@astralinux.ru>
Cc: "Xiaowei Song" <songxiaowei@hisilicon.com>,
	"Binghui Wang" <wangbinghui@hisilicon.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] PCI: kirin: Fix buffer overflow
Date: Fri, 12 Jul 2024 11:07:56 +0200	[thread overview]
Message-ID: <20240712110756.3abe1806@foz.lan> (raw)
In-Reply-To: <20240712084309.13248-1-adiupina@astralinux.ru>

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

  reply	other threads:[~2024-07-12  9:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12  8:43 [PATCH] PCI: kirin: Fix buffer overflow Alexandra Diupina
2024-07-12  9:07 ` Mauro Carvalho Chehab [this message]
2024-07-19 12:21   ` [PATCH v2] " Alexandra Diupina
2024-09-02 14:14     ` Alexandra Diupina
2024-09-02 17:17       ` Krzysztof Wilczyński
2024-09-02 18:29     ` Mauro Carvalho Chehab
  -- strict thread matches above, loose matches on Subject: below --
2024-09-03 11:58 [PATCH] " Alexandra Diupina
2024-09-06  6:42 ` Krzysztof Wilczyński

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240712110756.3abe1806@foz.lan \
    --to=mchehab+huawei@kernel.org \
    --cc=adiupina@astralinux.ru \
    --cc=bhelgaas@google.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=robh@kernel.org \
    --cc=songxiaowei@hisilicon.com \
    --cc=wangbinghui@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox