From: sashiko-bot@kernel.org
To: "Niklas Cassel" <cassel@kernel.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] misc: pci_endpoint_test: Add WARN_ON() to detect broken EPC drivers
Date: Wed, 29 Jul 2026 20:38:49 +0000 [thread overview]
Message-ID: <20260729203850.689781F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729202821.1153443-2-cassel@kernel.org>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] The newly added `WARN_ON` can be trivially triggered by shared interrupts or untrusted hardware, leading to a Denial of Service (host panic) if `panic_on_warn` is enabled.
- [Medium] Direct, lockless read of the internal `done` field in `struct completion` causes a data race, violates API encapsulation, and relies on a flawed TOCTOU heuristic.
Pre-existing issues:
- [High] The shared IRQ handler unconditionally returns `IRQ_HANDLED` even when the interrupt was not generated by this device.
- [High] Use-after-free of `struct pci_endpoint_test` when the PCI device is unbound while a file descriptor is still open.
--
--- Patch [1]: [PATCH] misc: pci_endpoint_test: Add WARN_ON() to detect broken EPC drivers ---
commit e4f6d6484e68c6a478412d97f6734cf8590a6f97
Author: Niklas Cassel <cassel@kernel.org>
misc: pci_endpoint_test: Add WARN_ON() to detect broken EPC drivers
This commit adds a WARN_ON check to the IRQ handler in the PCI endpoint
test driver. It aims to detect if the driver receives multiple interrupts
sequentially without a successful wait in between.
> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index 3635741c3e7a7..a212e53654c68 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
> @@ -178,6 +178,19 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id)
> if (reg & STATUS_IRQ_RAISED) {
> test->last_irq = irq;
> complete(&test->irq_raised);
> + /*
> + * The endpoint test driver performs all testing sequentially.
> + * This means that test->irq_raised.done should never exceed 1.
> + * If it does, then we received two IRQs in a row, without a
> + * successful wait_for_completion_timeout() call in between.
> + *
> + * While complete() increases test->irq_raised.done by one,
> + * wait_for_completion_timeout() reduces test->irq_raised.done
> + * by one on success.
> + *
> + * Please debug your EPC driver if you see this warning.
> + */
> + WARN_ON(test->irq_raised.done > 1);
[Severity: Medium]
Does this direct, lockless read of the completion structure's internal state
introduce a data race?
If wait_for_completion_timeout() executes concurrently on another CPU between
the complete() call and this check, it could decrement done back to 0. Would
this window result in missing the duplicate IRQ this is attempting to detect?
[Severity: High]
Can this warning be trivially triggered by shared interrupts or untrusted
hardware?
If the driver requests its IRQ with IRQF_SHARED, an interrupt from another
device could cause this handler to execute. If it reads a stale
STATUS_IRQ_RAISED bit, could repeated shared interrupts trigger this WARN_ON
and potentially panic the host if panic_on_warn is enabled?
> }
>
> return IRQ_HANDLED;
[Severity: High]
This isn't a bug introduced by this patch, but does this function
unconditionally return IRQ_HANDLED even when the interrupt wasn't generated
by this device?
If the status register does not have STATUS_IRQ_RAISED set, bypassing the
internal block, returning IRQ_HANDLED instead of IRQ_NONE could mask
unhandled interrupts from other devices sharing the same IRQ line.
[ ... ]
[Severity: High]
This is a pre-existing issue, but does using devm_kzalloc() for the state
structure expose a use-after-free regression during device unbind?
If the PCI device is unbound, devm_kzalloc() frees the struct
pci_endpoint_test upon return from pci_endpoint_test_remove(). However, if
an application still holds the device node open, could a subsequent
ioctl() access the freed pointer when resolving the private data?
drivers/misc/pci_endpoint_test.c:pci_endpoint_test_ioctl() {
...
struct pci_endpoint_test *test = to_endpoint_test(file->private_data);
struct pci_dev *pdev = test->pdev;
mutex_lock(&test->mutex);
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260729202821.1153443-2-cassel@kernel.org?part=1
next prev parent reply other threads:[~2026-07-29 20:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 20:28 [PATCH] misc: pci_endpoint_test: Add WARN_ON() to detect broken EPC drivers Niklas Cassel
2026-07-29 20:38 ` sashiko-bot [this message]
2026-07-29 20:49 ` DWC eDMA weirdness Niklas Cassel
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=20260729203850.689781F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--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