* [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range
@ 2018-12-17 20:22 Souptick Joarder
2018-12-18 9:37 ` Russell King - ARM Linux
0 siblings, 1 reply; 3+ messages in thread
From: Souptick Joarder @ 2018-12-17 20:22 UTC (permalink / raw)
To: akpm, willy, mhocko, linux, robin.murphy, iamjoonsoo.kim,
treding, keescook, m.szyprowski
Cc: linux-mm, linux-kernel, linux-arm-kernel
Convert to use vm_insert_range() to map range of kernel
memory to user vma.
Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
---
arch/arm/mm/dma-mapping.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 661fe48..7cbcde5 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs)
{
- unsigned long uaddr = vma->vm_start;
- unsigned long usize = vma->vm_end - vma->vm_start;
+ unsigned long page_count = vma_pages(vma);
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;
+ int err;
if (!pages)
return -ENXIO;
- if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
+ if (off >= nr_pages)
return -ENXIO;
pages += off;
+ err = vm_insert_range(vma, vma->vm_start, pages, page_count);
+ if (err)
+ pr_err("Remapping memory failed: %d\n", err);
- do {
- int ret = vm_insert_page(vma, uaddr, *pages++);
- if (ret) {
- pr_err("Remapping memory failed: %d\n", ret);
- return ret;
- }
- uaddr += PAGE_SIZE;
- usize -= PAGE_SIZE;
- } while (usize > 0);
-
- return 0;
+ return err;
}
static int arm_iommu_mmap_attrs(struct device *dev,
struct vm_area_struct *vma, void *cpu_addr,
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range
2018-12-17 20:22 [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Souptick Joarder
@ 2018-12-18 9:37 ` Russell King - ARM Linux
2018-12-18 12:57 ` Souptick Joarder
0 siblings, 1 reply; 3+ messages in thread
From: Russell King - ARM Linux @ 2018-12-18 9:37 UTC (permalink / raw)
To: Souptick Joarder
Cc: mhocko, keescook, linux-kernel, willy, linux-mm, akpm, treding,
robin.murphy, iamjoonsoo.kim, linux-arm-kernel, m.szyprowski
On Tue, Dec 18, 2018 at 01:52:09AM +0530, Souptick Joarder wrote:
> Convert to use vm_insert_range() to map range of kernel
> memory to user vma.
>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> ---
> arch/arm/mm/dma-mapping.c | 21 +++++++--------------
> 1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 661fe48..7cbcde5 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma
> void *cpu_addr, dma_addr_t dma_addr, size_t size,
> unsigned long attrs)
> {
> - unsigned long uaddr = vma->vm_start;
> - unsigned long usize = vma->vm_end - vma->vm_start;
> + unsigned long page_count = vma_pages(vma);
> struct page **pages = __iommu_get_pages(cpu_addr, attrs);
> unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> unsigned long off = vma->vm_pgoff;
> + int err;
>
> if (!pages)
> return -ENXIO;
>
> - if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
> + if (off >= nr_pages)
> return -ENXIO;
Are you sure you can make this change?
You are restricting the offset to be within 0..nr_pages which ensures
that the initial struct page that is passed to vm_insert_range() is
valid, but I think the removal of the following check is unsafe.
Your new vm_insert_range() function only checks page_count <=
vma_pages(vma), which it will be since it _is_ vma_pages(vma). With
the removal of the second condition, there will be nothing checking
that (eg) off may be nr_pages - 1, and page_count=50, meaning that
vm_insert_range() will walk off the end of the page array.
Please take another look at this.
What about the other callsites of your new function - do they have
the same issue?
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range
2018-12-18 9:37 ` Russell King - ARM Linux
@ 2018-12-18 12:57 ` Souptick Joarder
0 siblings, 0 replies; 3+ messages in thread
From: Souptick Joarder @ 2018-12-18 12:57 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: Michal Hocko, Kees Cook, linux-kernel, Matthew Wilcox, Linux-MM,
Andrew Morton, treding, robin.murphy, iamjoonsoo.kim,
linux-arm-kernel, Marek Szyprowski
On Tue, Dec 18, 2018 at 3:08 PM Russell King - ARM Linux
<linux@armlinux.org.uk> wrote:
>
> On Tue, Dec 18, 2018 at 01:52:09AM +0530, Souptick Joarder wrote:
> > Convert to use vm_insert_range() to map range of kernel
> > memory to user vma.
> >
> > Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> > ---
> > arch/arm/mm/dma-mapping.c | 21 +++++++--------------
> > 1 file changed, 7 insertions(+), 14 deletions(-)
> >
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index 661fe48..7cbcde5 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma
> > void *cpu_addr, dma_addr_t dma_addr, size_t size,
> > unsigned long attrs)
> > {
> > - unsigned long uaddr = vma->vm_start;
> > - unsigned long usize = vma->vm_end - vma->vm_start;
> > + unsigned long page_count = vma_pages(vma);
> > struct page **pages = __iommu_get_pages(cpu_addr, attrs);
> > unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> > unsigned long off = vma->vm_pgoff;
> > + int err;
> >
> > if (!pages)
> > return -ENXIO;
> >
> > - if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
> > + if (off >= nr_pages)
> > return -ENXIO;
>
> Are you sure you can make this change?
>
> You are restricting the offset to be within 0..nr_pages which ensures
> that the initial struct page that is passed to vm_insert_range() is
> valid, but I think the removal of the following check is unsafe.
>
> Your new vm_insert_range() function only checks page_count <=
> vma_pages(vma), which it will be since it _is_ vma_pages(vma). With
> the removal of the second condition, there will be nothing checking
> that (eg) off may be nr_pages - 1, and page_count=50, meaning that
> vm_insert_range() will walk off the end of the page array.
>
> Please take another look at this.
This check shouldn't be removed.
>
> What about the other callsites of your new function - do they have
> the same issue?
I think other callsites don't have the same issue.
>
> --
> RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
> FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
> According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-12-18 12:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-17 20:22 [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Souptick Joarder
2018-12-18 9:37 ` Russell King - ARM Linux
2018-12-18 12:57 ` Souptick Joarder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).