Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hans Zhang" <18255117159@163.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH 4/9] PCI: brcmstb: Protect root bus removal with rescan lock
Date: Thu, 21 May 2026 19:19:55 +0000	[thread overview]
Message-ID: <20260521191955.C5CFC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260521161822.132996-5-18255117159@163.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Calling `brcm_pcie_remove()` on the `pci_host_probe()` error path triggers a Use-After-Free (UAF) or NULL pointer dereference.
- [High] The `pcie->bridge_lock` is used before it is initialized during device probe.
--

commit baacf34014bfc48de11be2860d0ae507bf20e383
Author: Hans Zhang <18255117159@163.com>

PCI: brcmstb: Protect root bus removal with rescan lock

Add missing PCI rescan lock protection in brcm_pcie_remove() before
removing the root bus.

> diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
> index 714bcab97b603..7ca27f0756c9b 100644
> --- a/drivers/pci/controller/pcie-brcmstb.c
> +++ b/drivers/pci/controller/pcie-brcmstb.c
> @@ -1894,8 +1894,10 @@ static void brcm_pcie_remove(struct platform_device *pdev)
>  	struct brcm_pcie *pcie = platform_get_drvdata(pdev);
>  	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
>  
> +	pci_lock_rescan_remove();
>  	pci_stop_root_bus(bridge->bus);

[Severity: Critical]
This is a pre-existing issue, but can calling brcm_pcie_remove() on the
pci_host_probe() error path trigger a use-after-free or null pointer
dereference here?

In brcm_pcie_probe(), if pci_host_probe() fails, the error path directly
calls brcm_pcie_remove(). If pci_host_probe() failed early because
pci_alloc_bus() returned null, bridge->bus remains null. If it failed later
during pci_register_host_bridge(), the allocated bus is freed via kfree(),
but bridge->bus is never cleared, leaving it as a dangling pointer.

When brcm_pcie_remove() is invoked, it unconditionally calls
pci_stop_root_bus(bridge->bus). Passing a null or dangling pointer here
causes a kernel crash on the probe error path.

>  	pci_remove_root_bus(bridge->bus);
> +	pci_unlock_rescan_remove();
>  	if (pcie->cfg->has_err_report)
>  		brcm_unregister_die_notifiers(pcie);

[Severity: High]
This is a pre-existing issue, but is pcie->bridge_lock used before it is
initialized during device probe?

During brcm_pcie_probe(), the function brcm_pcie_bridge_sw_init_set() is
called early in the initialization sequence. For devices where
pcie->cfg->has_err_report is true, this function acquires pcie->bridge_lock
via spin_lock_irqsave().

However, spin_lock_init(&pcie->bridge_lock) is not called until much later
in the probe sequence, after pci_host_probe() finishes. While the memory is
zero-initialized, unconditionally attempting to acquire an uninitialized
spinlock is structurally unsafe and can trigger lockdep warnings or crashes.

>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260521161822.132996-1-18255117159@163.com?part=4

  reply	other threads:[~2026-05-21 19:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 16:18 [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal Hans Zhang
2026-05-21 16:18 ` [PATCH 1/9] PCI: cadence: Protect root bus removal with rescan lock Hans Zhang
2026-05-21 16:18 ` [PATCH 2/9] PCI: dwc: " Hans Zhang
2026-05-21 16:18 ` [PATCH 3/9] PCI: altera: " Hans Zhang
2026-05-21 18:51   ` sashiko-bot
2026-05-21 16:18 ` [PATCH 4/9] PCI: brcmstb: " Hans Zhang
2026-05-21 19:19   ` sashiko-bot [this message]
2026-05-21 16:18 ` [PATCH 5/9] PCI: iproc: " Hans Zhang
2026-05-21 16:18 ` [PATCH 6/9] PCI: mediatek: " Hans Zhang
2026-05-21 20:11   ` sashiko-bot
2026-05-21 16:18 ` [PATCH 7/9] PCI: rockchip: " Hans Zhang
2026-05-21 20:40   ` sashiko-bot
2026-05-21 16:18 ` [PATCH 8/9] PCI: vmd: " Hans Zhang
2026-05-21 21:20   ` sashiko-bot
2026-06-10 17:28     ` Manivannan Sadhasivam
2026-06-11  4:42       ` Hans Zhang
2026-06-11  6:30         ` Manivannan Sadhasivam
2026-06-11 14:00           ` Hans Zhang
2026-05-21 16:18 ` [PATCH 9/9] PCI: plda: " Hans Zhang
2026-06-11  7:04 ` (subset) [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal Manivannan Sadhasivam
2026-06-18 16:59 ` Bjorn Helgaas

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=20260521191955.C5CFC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=18255117159@163.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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