Skip to content

Commit 1137e61

Browse files
Niklas CasselLorenzo Pieralisi
authored andcommitted
PCI: dwc: Fix find_next_bit() usage
find_next_bit() takes a parameter of size long, and performs arithmetic that assumes that the argument is of size long. Therefore we cannot pass a u32, since this will cause find_next_bit() to read outside the stack buffer and will produce the following print: BUG: KASAN: stack-out-of-bounds in find_next_bit+0x38/0xb0 Fixes: 1b497e6 ("PCI: dwc: Fix uninitialized variable in dw_handle_msi_irq()") Tested-by: Bjorn Andersson <[email protected]> Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Reviewed-by: Andrew Murray <[email protected]> Acked-by: Gustavo Pimentel <[email protected]>
1 parent 54ecb8f commit 1137e61

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/pci/controller/dwc/pcie-designware-host.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,23 @@ static struct msi_domain_info dw_pcie_msi_domain_info = {
7878
irqreturn_t dw_handle_msi_irq(struct pcie_port *pp)
7979
{
8080
int i, pos, irq;
81-
u32 val, num_ctrls;
81+
unsigned long val;
82+
u32 status, num_ctrls;
8283
irqreturn_t ret = IRQ_NONE;
8384

8485
num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
8586

8687
for (i = 0; i < num_ctrls; i++) {
8788
dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_STATUS +
8889
(i * MSI_REG_CTRL_BLOCK_SIZE),
89-
4, &val);
90-
if (!val)
90+
4, &status);
91+
if (!status)
9192
continue;
9293

9394
ret = IRQ_HANDLED;
95+
val = status;
9496
pos = 0;
95-
while ((pos = find_next_bit((unsigned long *) &val,
96-
MAX_MSI_IRQS_PER_CTRL,
97+
while ((pos = find_next_bit(&val, MAX_MSI_IRQS_PER_CTRL,
9798
pos)) != MAX_MSI_IRQS_PER_CTRL) {
9899
irq = irq_find_mapping(pp->irq_domain,
99100
(i * MAX_MSI_IRQS_PER_CTRL) +

0 commit comments

Comments
 (0)