From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH] hw/pci/pci.c: Assert that pci_irq_handler() inputs are valid
Date: Tue, 23 Mar 2021 16:46:01 +0000 [thread overview]
Message-ID: <20210323164601.27200-1-peter.maydell@linaro.org> (raw)
pci_irq_handler documents that it must be called with 0 <= irq_num <=
3 and level either 0 or 1. Add assertions that the caller has passed
us in valid arguments.
In particular, if a device model fails to set the PCI_INTERRUPT_PIN
field in its config space correctly to indicate that it has an
interrupt, and then tries to raise an interrupt (either by calling
pci_set_irq(), or by getting a qemu_irq from pci_allocate_irq() and
then calling qemu_set_irq() on that) we will now diagnose this device
model bug with an assertion rather than engaging in the undefined
behaviour of shifting by a negative number.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/pci/pci.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 0eadcdbc9ec..38aefe22ab3 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1449,6 +1449,9 @@ static void pci_irq_handler(void *opaque, int irq_num, int level)
PCIDevice *pci_dev = opaque;
int change;
+ assert(irq_num >= 0 && irq_num < PCI_NUM_PINS);
+ assert(level == 0 || level == 1);
+
change = level - pci_irq_state(pci_dev, irq_num);
if (!change)
return;
--
2.20.1
next reply other threads:[~2021-03-23 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-23 16:46 Peter Maydell [this message]
2021-03-23 20:47 ` [PATCH] hw/pci/pci.c: Assert that pci_irq_handler() inputs are valid Philippe Mathieu-Daudé
2021-03-24 16:21 ` Isaku Yamahata
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=20210323164601.27200-1-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).