From: sashiko-bot@kernel.org
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: linux-pci@vger.kernel.org, wsa+renesas@sang-engineering.com
Subject: Re: [PATCH v2 3/3] PCI: rzg3s: Fix IRQ domain initialization error handling
Date: Mon, 27 Jul 2026 10:35:27 +0000 [thread overview]
Message-ID: <20260727103527.DBDDC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727095843.116950-4-prabhakar.mahadev-lad.rj@bp.renesas.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The err_cleanup_intx error path destroys the INTx IRQ domain before clearing the active chained handlers, creating a use-after-free race.
Pre-existing issues:
- [High] rzg3s_pcie_intx_irq_handler() incorrectly assumes Linux virtual IRQ numbers are contiguous, which can lead to out-of-bounds domain mapping lookups and interrupt storms.
--
--- Patch [3]: [PATCH v2 3/3] PCI: rzg3s: Fix IRQ domain initialization error handling ---
commit 895e108af15957f16a4f68cbf1072bd988ee57dc
Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
PCI: rzg3s: Fix IRQ domain initialization error handling
This commit attempts to fix a resource leak by unwinding chained handler
registrations on error paths in rzg3s_pcie_init_irqdomain(). It also adds
teardown logic to clear the handlers, mirroring the initialization sequence.
Cc: stable@vger.kernel.org
> diff --git a/drivers/pci/controller/pcie-rzg3s-host.c b/drivers/pci/controller/pcie-rzg3s-host.c
> index f51b5d7c19983..70f1faf7e4227 100644
> --- a/drivers/pci/controller/pcie-rzg3s-host.c
> +++ b/drivers/pci/controller/pcie-rzg3s-host.c
[ ... ]
> @@ -1006,22 +1006,35 @@ static const struct irq_domain_ops rzg3s_pcie_intx_domain_ops = {
[ ... ]
> static int rzg3s_pcie_init_irqdomain(struct rzg3s_pcie_host *host)
> {
> struct device *dev = host->dev;
> struct platform_device *pdev = to_platform_device(dev);
> + int i, ret;
>
> - for (int i = 0; i < PCI_NUM_INTX; i++) {
> + for (i = 0; i < PCI_NUM_INTX; i++) {
> char irq_name[5] = {0};
> int irq;
>
> scnprintf(irq_name, ARRAY_SIZE(irq_name), "int%c", 'a' + i);
>
> irq = platform_get_irq_byname(pdev, irq_name);
> - if (irq < 0)
> - return dev_err_probe(dev, irq,
> - "Failed to parse and map INT%c IRQ\n",
> - 'A' + i);
> + if (irq < 0) {
> + ret = irq;
> + dev_err_probe(dev, ret,
> + "Failed to parse and map INT%c IRQ\n",
> + 'A' + i);
> + goto err_cleanup_intx;
> + }
>
> host->intx_irqs[i] = irq;
> irq_set_chained_handler_and_data(irq,
> rzg3s_pcie_intx_irq_handler,
> host);
> }
[Severity: High]
This is a pre-existing issue, but does this code assume that the Linux virtual
IRQ numbers returned by platform_get_irq_byname() are always contiguous?
Looking at rzg3s_pcie_intx_irq_handler():
drivers/pci/controller/pcie-rzg3s-host.c:rzg3s_pcie_intx_irq_handler() {
...
unsigned int irq = irq_desc_get_irq(desc);
u32 intx = irq - host->intx_irqs[0];
chained_irq_enter(chip, desc);
generic_handle_domain_irq(host->intx_domain, intx);
...
}
If the dynamically allocated virtual IRQs are not strictly sequential, could
this calculation yield an out-of-bounds index for generic_handle_domain_irq()?
If the mapping fails to resolve, could the incoming level-triggered interrupt
remain unacknowledged, leading to an interrupt storm?
[ ... ]
> if (IS_ENABLED(CONFIG_PCI_MSI)) {
> - int ret = rzg3s_pcie_init_msi(host);
> + ret = rzg3s_pcie_init_msi(host);
>
> - if (ret) {
> - irq_domain_remove(host->intx_domain);
> - return ret;
> - }
> + if (ret)
> + goto err_cleanup_intx;
> }
>
> return 0;
> +
> +err_cleanup_intx:
> + if (host->intx_domain)
> + irq_domain_remove(host->intx_domain);
> + rzg3s_pcie_clear_intx_handlers(host, i);
[Severity: High]
Is there a race condition in this error path?
If MSI initialization fails, irq_domain_remove(host->intx_domain) is called
before rzg3s_pcie_clear_intx_handlers().
Since irq_set_chained_handler_and_data() was already called earlier, the
interrupts are unmasked and active.
If a hardware INTx interrupt fires before the handlers are cleared, could
rzg3s_pcie_intx_irq_handler() run and dereference the freed host->intx_domain
via generic_handle_domain_irq(), causing a use-after-free?
Should rzg3s_pcie_clear_intx_handlers() be called before destroying the IRQ
domain?
> +
> + return ret;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727095843.116950-1-prabhakar.mahadev-lad.rj@bp.renesas.com?part=3
prev parent reply other threads:[~2026-07-27 10:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 9:58 [PATCH v2 0/3] PCI: rzg3s: Fix issues in cleanup paths Prabhakar
2026-07-27 9:58 ` [PATCH v2 1/3] PCI: rzg3s: Disable refclk on probe failure Prabhakar
2026-07-27 10:15 ` sashiko-bot
2026-07-27 9:58 ` [PATCH v2 2/3] PCI: rzg3s: Propagate platform_get_irq_byname() errors Prabhakar
2026-07-27 10:23 ` sashiko-bot
2026-07-27 9:58 ` [PATCH v2 3/3] PCI: rzg3s: Fix IRQ domain initialization error handling Prabhakar
2026-07-27 10:35 ` sashiko-bot [this message]
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=20260727103527.DBDDC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=prabhakar.csengg@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wsa+renesas@sang-engineering.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.