From: Nagarjuna Kristam <nkristam@nvidia.com> To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, dmitry.torokhov@gmail.com Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Nagarjuna Kristam <nkristam@nvidia.com> Subject: [PATCH] USB: usbfs: check cpu address range before remap Date: Wed, 4 Sep 2019 13:47:31 +0530 [thread overview] Message-ID: <1567585051-1354-1-git-send-email-nkristam@nvidia.com> (raw) In usbfs mmap, usb_alloc_coherent is used to allocate memory. This Memory is then remapped to user space memory using remap_pfn_range. remap_pfn_range needs phy address of memory, for which virt_to_phy API is used. This API works only if memory is allocated using kmalloc. But usb_alloc_coherent can allocate memory in vmalloc range and this causes wrong remap of user memory. Check if address returned by usb_alloc_coherent failed in vmalloc range and if yes, use remap_vmalloc_range API, else use remap_pfn_range to remap address to user space. Signed-off-by: Nagarjuna Kristam <nkristam@nvidia.com> --- drivers/usb/core/devio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index a945ad7..20999de 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -250,7 +250,12 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) usbm->vma_use_count = 1; INIT_LIST_HEAD(&usbm->memlist); - if (remap_pfn_range(vma, vma->vm_start, + if (is_vmalloc_addr(usbm->mem)) { + if (remap_vmalloc_range(vma, usbm->mem, 0) < 0) { + dec_usb_memory_use_count(usbm, &usbm->vma_use_count); + return -EAGAIN; + } + } else if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(usbm->mem) >> PAGE_SHIFT, size, vma->vm_page_prot) < 0) { dec_usb_memory_use_count(usbm, &usbm->vma_use_count); -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Nagarjuna Kristam <nkristam@nvidia.com> To: <gregkh@linuxfoundation.org>, <stern@rowland.harvard.edu>, <dmitry.torokhov@gmail.com> Cc: <linux-tegra@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>, Nagarjuna Kristam <nkristam@nvidia.com> Subject: [PATCH] USB: usbfs: check cpu address range before remap Date: Wed, 4 Sep 2019 13:47:31 +0530 [thread overview] Message-ID: <1567585051-1354-1-git-send-email-nkristam@nvidia.com> (raw) In usbfs mmap, usb_alloc_coherent is used to allocate memory. This Memory is then remapped to user space memory using remap_pfn_range. remap_pfn_range needs phy address of memory, for which virt_to_phy API is used. This API works only if memory is allocated using kmalloc. But usb_alloc_coherent can allocate memory in vmalloc range and this causes wrong remap of user memory. Check if address returned by usb_alloc_coherent failed in vmalloc range and if yes, use remap_vmalloc_range API, else use remap_pfn_range to remap address to user space. Signed-off-by: Nagarjuna Kristam <nkristam@nvidia.com> --- drivers/usb/core/devio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index a945ad7..20999de 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -250,7 +250,12 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) usbm->vma_use_count = 1; INIT_LIST_HEAD(&usbm->memlist); - if (remap_pfn_range(vma, vma->vm_start, + if (is_vmalloc_addr(usbm->mem)) { + if (remap_vmalloc_range(vma, usbm->mem, 0) < 0) { + dec_usb_memory_use_count(usbm, &usbm->vma_use_count); + return -EAGAIN; + } + } else if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(usbm->mem) >> PAGE_SHIFT, size, vma->vm_page_prot) < 0) { dec_usb_memory_use_count(usbm, &usbm->vma_use_count); -- 2.7.4
next reply other threads:[~2019-09-04 8:17 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-09-04 8:17 Nagarjuna Kristam [this message] 2019-09-04 8:17 ` [PATCH] USB: usbfs: check cpu address range before remap Nagarjuna Kristam 2019-10-04 12:21 ` Greg KH
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=1567585051-1354-1-git-send-email-nkristam@nvidia.com \ --to=nkristam@nvidia.com \ --cc=dmitry.torokhov@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-tegra@vger.kernel.org \ --cc=linux-usb@vger.kernel.org \ --cc=stern@rowland.harvard.edu \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.