public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <mchristi@redhat.com>
To: xiubli@redhat.com, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org
Cc: hamish.martin@alliedtelesis.co.nz, jannh@google.com,
	pkalever@redhat.com, pkarampu@redhat.com, atumball@redhat.com,
	sabose@redhat.com
Subject: Re: [PATCH v3 3/3] uio: fix crash after the device is unregistered
Date: Fri, 6 Jul 2018 13:23:44 -0500	[thread overview]
Message-ID: <5B3FB3B0.7010105@redhat.com> (raw)
In-Reply-To: <1530845836-49101-4-git-send-email-xiubli@redhat.com>

On 07/05/2018 09:57 PM, xiubli@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.

  parent reply	other threads:[~2018-07-06 18:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06  2:57 [PATCH v3 0/3] uio: fix potential crash bug xiubli
2018-07-06  2:57 ` [PATCH v3 1/3] uio: use request_threaded_irq instead xiubli
2018-07-06  2:57 ` [PATCH v3 2/3] uio: change to use the mutex lock instead of the spin lock xiubli
2018-07-06  3:39   ` Hamish Martin
2018-07-06  2:57 ` [PATCH v3 3/3] uio: fix crash after the device is unregistered xiubli
2018-07-06  3:40   ` Hamish Martin
2018-07-06 18:23   ` Mike Christie [this message]
2018-07-07  1:28     ` Xiubo Li
2018-07-09 17:06       ` Mike Christie
2018-07-10  2:40         ` Xiubo Li
2018-07-06 18:58   ` Mike Christie
2018-07-07  1:47     ` Xiubo Li
2018-07-09 16:40       ` Mike Christie
2018-07-10  2:36         ` Xiubo Li
2018-07-06  3:31 ` [PATCH v3 0/3] uio: fix potential crash bug Hamish Martin
2018-07-06 12:04   ` Xiubo Li

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=5B3FB3B0.7010105@redhat.com \
    --to=mchristi@redhat.com \
    --cc=atumball@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hamish.martin@alliedtelesis.co.nz \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pkalever@redhat.com \
    --cc=pkarampu@redhat.com \
    --cc=sabose@redhat.com \
    --cc=xiubli@redhat.com \
    /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