Commit b7435128 authored by Jia-Ju Bai's avatar Jia-Ju Bai Committed by Greg Kroah-Hartman

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: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
Link: https://lore.kernel.org/r/20191218094405.6009-1-baijiaju1990@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fa4e7fc1
...@@ -132,11 +132,13 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on) ...@@ -132,11 +132,13 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
if (irq_on) { if (irq_on) {
if (test_and_clear_bit(0, &priv->flags)) if (test_and_clear_bit(0, &priv->flags))
enable_irq(dev_info->irq); enable_irq(dev_info->irq);
spin_unlock_irqrestore(&priv->lock, flags);
} else { } else {
if (!test_and_set_bit(0, &priv->flags)) if (!test_and_set_bit(0, &priv->flags)) {
spin_unlock_irqrestore(&priv->lock, flags);
disable_irq(dev_info->irq); disable_irq(dev_info->irq);
}
} }
spin_unlock_irqrestore(&priv->lock, flags);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment