On 07/05/2018 09:57 PM, xiu...@redhat.com wrote:
>  static irqreturn_t uio_interrupt(int irq, void *dev_id)
>  {
>       struct uio_device *idev = (struct uio_device *)dev_id;
> -     irqreturn_t ret = idev->info->handler(irq, idev->info);
> +     irqreturn_t ret;
> +
> +     mutex_lock(&idev->info_lock);
> +     if (!idev->info) {
> +             ret = IRQ_NONE;
> +             goto out;
> +     }
>  
> +     ret = idev->info->handler(irq, idev->info);
>       if (ret == IRQ_HANDLED)
>               uio_event_notify(idev->info);
>  
> +out:
> +     mutex_unlock(&idev->info_lock);
>       return ret;
>  }


Do you need the interrupt related changes in this patch and the first
one? When we do uio_unregister_device -> free_irq does free_irq return
when there are no longer running interrupt handlers that we requested?

If that is not the case then I think we can hit a similar bug. We do:

__uio_register_device -> device_register -> device's refcount goes to
zero so we do -> uio_device_release -> kfree(idev)

and if it is possible the interrupt handler could still run after
free_irq then we would end up doing:

uio_interrupt -> mutex_lock(&idev->info_lock) -> idev access freed memory.

Reply via email to