From: Tong Zhang <ztong0001@gmail.com>
To: Marc Zyngier <maz@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Jason Gunthorpe <jgg@ziepe.ca>,
linux-kernel@vger.kernel.org
Cc: Tong Zhang <ztong0001@gmail.com>
Subject: [PATCH v1] genirq/msi: fix crash when handling Multi-MSI
Date: Mon, 17 Jan 2022 01:27:59 -0800 [thread overview]
Message-ID: <20220117092759.1619771-1-ztong0001@gmail.com> (raw)
pci_msi_domain_check_cap() could return 1 when domain does not support
multi MSI and user request multi MSI. This positive value will be used by
__pci_enable_msi_range(). In previous refactor, this positive value is
handled as error case which will cause kernel crash.
[ 1.197953] BUG: KASAN: use-after-free in __pci_enable_msi_range+0x234/0x320
[ 1.198327] Freed by task 1:
[ 1.198327] kfree+0x8f/0x2b0
[ 1.198327] msi_free_msi_descs_range+0xf5/0x130
[ 1.198327] msi_domain_alloc_irqs_descs_locked+0x8d/0xa0
[ 1.198327] __pci_enable_msi_range+0x1a4/0x320
[ 1.198327] pci_alloc_irq_vectors_affinity+0x135/0x1a0
[ 1.198327] pcie_port_device_register+0x4a1/0x5c0
[ 1.198327] pcie_portdrv_probe+0x50/0x100
Fixes: 0f62d941acf9 ("genirq/msi: Provide msi_domain_alloc/free_irqs_descs_locked()")
Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
kernel/irq/msi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 2bdfce5edafd..57b1447a3bf1 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -935,7 +935,7 @@ int msi_domain_alloc_irqs_descs_locked(struct irq_domain *domain, struct device
return ret;
ret = ops->domain_alloc_irqs(domain, dev, nvec);
- if (ret)
+ if (ret < 0)
msi_domain_free_irqs_descs_locked(domain, dev);
return ret;
}
--
2.25.1
next reply other threads:[~2022-01-17 9:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 9:27 Tong Zhang [this message]
2022-01-17 9:59 ` Marc Zyngier
2022-01-17 10:10 ` Tong Zhang
2022-01-17 11:36 ` Marc Zyngier
2022-01-18 14:39 ` Thomas Gleixner
2022-01-19 0:44 ` Thomas Gleixner
2022-01-19 17:54 ` [PATCH] PCI/MSI: Prevent UAF in error path Thomas Gleixner
2022-01-19 18:37 ` Bjorn Helgaas
2022-01-19 18:54 ` Tong Zhang
2022-01-21 1:18 ` [tip: irq/urgent] " tip-bot2 for Thomas Gleixner
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=20220117092759.1619771-1-ztong0001@gmail.com \
--to=ztong0001@gmail.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=tglx@linutronix.de \
/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®