mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiubo Li <xiubli@redhat.com>
To: Jann Horn <jannh@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kernel list <linux-kernel@vger.kernel.org>,
	pkalever@redhat.com, pkarampu@redhat.com, atumball@redhat.com,
	sabose@redhat.com, mchristi@redhat.com
Subject: Re: [PATCH 2/2] uio: fix crash after the device is unregistered
Date: Fri, 6 Jul 2018 07:23:15 +0800	[thread overview]
Message-ID: <2b211654-19d0-8001-d829-a3c640755348@redhat.com> (raw)
In-Reply-To: <CAG48ez1Ze1Q08HtyC8PyhW5msQ8qwFDy6eDj8s9k_j4vmG7nJw@mail.gmail.com>

On 2018/7/6 4:56, Jann Horn wrote:
> On Thu, Jul 5, 2018 at 10:53 PM <xiubli@redhat.com> wrote:
>> From: Xiubo Li <xiubli@redhat.com>
>>
>> For the target_core_user use case, after the device is unregistered
>> it maybe still opened in user space, then the kernel will crash, like:
>>
> [...]
>> Signed-off-by: Xiubo Li <xiubli@redhat.com>
>> ---
>>   drivers/uio/uio.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++--------
>>   1 file changed, 86 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
>> index 33c3bfe..2b9268a 100644
>> --- a/drivers/uio/uio.c
>> +++ b/drivers/uio/uio.c
> [...]
>> @@ -720,30 +775,46 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
>>
>>          vma->vm_private_data = idev;
>>
>> +       mutex_lock(&idev->info_lock);
>> +       if (!idev->info) {
>> +               ret = -EINVAL;
>> +               goto out;
>> +       }
>> +
>>          mi = uio_find_mem_index(vma);
>> -       if (mi < 0)
>> -               return -EINVAL;
>> +       if (mi < 0) {
>> +               ret = -EINVAL;
>> +               goto out;
>> +       }
>>
>>          requested_pages = vma_pages(vma);
>>          actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
>>                          + idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
>> -       if (requested_pages > actual_pages)
>> -               return -EINVAL;
>> +       if (requested_pages > actual_pages) {
>> +               ret = -EINVAL;
>> +               goto out;
>> +       }
>>
>>          if (idev->info->mmap) {
>>                  ret = idev->info->mmap(idev->info, vma);
>> -               return ret;
>> +               goto out;
>>          }
>>
>>          switch (idev->info->mem[mi].memtype) {
>>                  case UIO_MEM_PHYS:
>> -                       return uio_mmap_physical(vma);
>> +                       ret = uio_mmap_physical(vma);
>> +                       break;
>>                  case UIO_MEM_LOGICAL:
>>                  case UIO_MEM_VIRTUAL:
>> -                       return uio_mmap_logical(vma);
>> +                       ret = uio_mmap_logical(vma);
>> +                       break;
>>                  default:
>> -                       return -EINVAL;
>> +                       ret = -EINVAL;
>>          }
>> +
>> +out:
>> +       mutex_lock(&idev->info_lock);
> This is probably supposed to be mutex_unlock(...)?

Yeah yeah, right, Good catch :-)

Locally I had fixed this, but after my building and testing just forgot 
to amend it.

Will fix it.

Thanks very much.

BRs


      reply	other threads:[~2018-07-05 23:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05 16:27 [PATCH 0/2] uio: fix potential crash bug xiubli
2018-07-05 16:27 ` [PATCH 1/2] uio: change to use the mutex lock instead of the spin lock xiubli
2018-07-05 16:33   ` Greg KH
2018-07-05 23:21     ` Xiubo Li
2018-07-05 16:27 ` [PATCH 2/2] uio: fix crash after the device is unregistered xiubli
2018-07-05 20:56   ` Jann Horn
2018-07-05 23:23     ` Xiubo Li [this message]

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=2b211654-19d0-8001-d829-a3c640755348@redhat.com \
    --to=xiubli@redhat.com \
    --cc=atumball@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchristi@redhat.com \
    --cc=pkalever@redhat.com \
    --cc=pkarampu@redhat.com \
    --cc=sabose@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

all inboxes | Powered by JetHome®