From: <shao.mingyin@zte.com.cn>
To: <bhelgaas@google.com>, <linux-pci@vger.kernel.org>
Cc: <mani@kernel.org>, <kwilczynski@kernel.org>,
<lpieralisi@kernel.org>, <kishon@kernel.org>,
<Frank.Li@kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 5/5] PCI: endpoint: Reject a zero interrupt number in raise_irq
Date: Sat, 7 Nov 2026 00:23:16 +0800 (CST) [thread overview]
Message-ID: <20261107002316495thppDxT_WC_3QyEVfQn0e@zte.com.cn> (raw)
In-Reply-To: <20261107002305850zuBaVsGBz3wbco2Ae4ScR@zte.com.cn>
From: Shao Mingyin <shao.mingyin@zte.com.cn>
pci_epc_raise_irq() passes interrupt_num straight through to the
controller's raise_irq callback. The DWC and other controllers compute
"msg_data | (interrupt_num - 1)" for MSI/MSI-X, so an interrupt_num of 0
underflows to 65535 and raises a message with a bogus vector that no
configured MSI/MSI-X entry matches.
Reject interrupt_num == 0 for the MSI and MSI-X types in the core API.
INTx raises use interrupt_num 0 and are unaffected.
Fixes: 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
Tested on 7.3.0-next-20261030 (QEMU/TCG guest). QEMU has no PCI EP
controller model, so a TEST-ONLY hook (applied to both kernels, not part
of this patch) fabricates a pci_epc whose ops->raise_irq records whether
it is called, then drives pci_epc_raise_irq() with interrupt_num 0 for
MSI and MSI-X. Without this fix both reach the controller callback (the
DWC style "msg_data | (interrupt_num - 1)" would underflow to 65535);
with this fix both are rejected with -EINVAL while INTx (interrupt_num 0)
still reaches the callback unchanged.
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 831b40458dcd..d8e5dd6355ac 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -295,6 +295,10 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
return -EINVAL;
+ if ((type == PCI_IRQ_MSI || type == PCI_IRQ_MSIX) &&
+ !interrupt_num)
+ return -EINVAL;
+
if (!epc->ops->raise_irq)
return 0;
prev parent reply other threads:[~2026-11-06 16:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:23 [PATCH 0/5] PCI: Fix invalid input handling and a NULL dereference shao.mingyin
2026-11-06 16:23 ` [PATCH 1/5] PCI: Reject negative resource alignment order shao.mingyin
2026-11-06 16:39 ` Ilpo Järvinen
2026-11-06 17:13 ` shao.mingyin
2026-11-06 16:23 ` [PATCH 2/5] PCI: of: Bound num_lanes in of_pci_get_equalization_presets() shao.mingyin
2026-11-06 16:23 ` [PATCH 3/5] PCI/ASPM: Skip link-state setup without downstream function 0 shao.mingyin
2026-11-06 16:23 ` [PATCH 4/5] PCI: rebar: Guard pci_rebar_bytes_to_size() against overflow shao.mingyin
2026-11-06 16:37 ` Ilpo Järvinen
2026-11-06 17:11 ` shao.mingyin
2026-11-06 16:23 ` shao.mingyin [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=20261107002316495thppDxT_WC_3QyEVfQn0e@zte.com.cn \
--to=shao.mingyin@zte.com.cn \
--cc=Frank.Li@kernel.org \
--cc=bhelgaas@google.com \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
/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
all inboxes | Powered by JetHome®