Skip to content

Commit b743512

Browse files
XidianGeneralgregkh
authored andcommitted
uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol()
The driver may sleep while holding a spinlock. The function call path (from bottom to top) in Linux 4.19 is: kernel/irq/manage.c, 523: synchronize_irq in disable_irq drivers/uio/uio_dmem_genirq.c, 140: disable_irq in uio_dmem_genirq_irqcontrol drivers/uio/uio_dmem_genirq.c, 134: _raw_spin_lock_irqsave in uio_dmem_genirq_irqcontrol synchronize_irq() can sleep at runtime. To fix this bug, disable_irq() is called without holding the spinlock. This bug is found by a static analysis tool STCheck written by myself. Signed-off-by: Jia-Ju Bai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fa4e7fc commit b743512

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/uio/uio_dmem_genirq.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
132132
if (irq_on) {
133133
if (test_and_clear_bit(0, &priv->flags))
134134
enable_irq(dev_info->irq);
135+
spin_unlock_irqrestore(&priv->lock, flags);
135136
} else {
136-
if (!test_and_set_bit(0, &priv->flags))
137+
if (!test_and_set_bit(0, &priv->flags)) {
138+
spin_unlock_irqrestore(&priv->lock, flags);
137139
disable_irq(dev_info->irq);
140+
}
138141
}
139-
spin_unlock_irqrestore(&priv->lock, flags);
140142

141143
return 0;
142144
}

0 commit comments

Comments
 (0)