Commit 98cc6d31 authored by Marek Szyprowski's avatar Marek Szyprowski Committed by Greg Kroah-Hartman

ARM: 8426/1: dma-mapping: add missing range check in dma_mmap()

commit 371f0f08 upstream.

dma_mmap() function in IOMMU-based dma-mapping implementation lacked
a check for valid range of mmap parameters (offset and buffer size), what
might have caused access beyond the allocated buffer. This patch fixes
this issue.
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c79f6268
...@@ -1355,12 +1355,17 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, ...@@ -1355,12 +1355,17 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
unsigned long uaddr = vma->vm_start; unsigned long uaddr = vma->vm_start;
unsigned long usize = vma->vm_end - vma->vm_start; unsigned long usize = vma->vm_end - vma->vm_start;
struct page **pages = __iommu_get_pages(cpu_addr, attrs); struct page **pages = __iommu_get_pages(cpu_addr, attrs);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;
vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot);
if (!pages) if (!pages)
return -ENXIO; return -ENXIO;
if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
return -ENXIO;
do { do {
int ret = vm_insert_page(vma, uaddr, *pages++); int ret = vm_insert_page(vma, uaddr, *pages++);
if (ret) { if (ret) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment