From: Marek Szyprowski Date: Fri, 28 Aug 2015 08:41:39 +0000 (+0100) Subject: ARM: 8426/1: dma-mapping: add missing range check in dma_mmap() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=371f0f085f629fc0f66695f572373ca4445a67ad;p=openwrt%2Fstaging%2Fblogic.git ARM: 8426/1: dma-mapping: add missing range check in dma_mmap() 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: Marek Szyprowski Cc: stable@vger.kernel.org # v3.6+ Signed-off-by: Russell King --- diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 1a7815e5421b..c0865867ef0d 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1407,12 +1407,17 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, unsigned long uaddr = vma->vm_start; unsigned long usize = vma->vm_end - vma->vm_start; 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); if (!pages) return -ENXIO; + if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off) + return -ENXIO; + do { int ret = vm_insert_page(vma, uaddr, *pages++); if (ret) {