From patchwork Mon Jul 30 08:29:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 1253751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 429B83FCFC for ; Mon, 30 Jul 2012 08:44:47 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SvlV7-00074b-Mb; Mon, 30 Jul 2012 08:38:53 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SvlN2-00050u-EX for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2012 08:30:33 +0000 Received: from epcpsbgm2.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M7Y0002HSXY37T0@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2012 17:30:07 +0900 (KST) X-AuditID: cbfee61b-b7f566d000005c8a-49-5016460f47e1 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 88.E8.23690.F0646105; Mon, 30 Jul 2012 17:30:07 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M7Y0073DSXY2S60@mmp2.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2012 17:30:07 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH] ARM: dma-mapping: add more sanity checks in arm_dma_mmap() Date: Mon, 30 Jul 2012 10:29:52 +0200 Message-id: <1343636992-19774-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.10 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBJMWRmVeSWpSXmKPExsVy+t9jQV1+N7EAg22zxCw2Pb7G6sDosXlJ fQBjFJdNSmpOZllqkb5dAldGw021gkdcFVefKzUwnuToYuTkkBAwkZh/fy4zhC0mceHeerYu Ri4OIYHpjBKL3uxggXA2M0lcPP+GDaSKTcBQouttF5gtIuAh8WTFObBuZoHXTBI/LtaD2MIC 3hITLr4Gi7MIqErsv7GPEcTmBar/M2EDI8Q2eYmn9/vYJjByL2BkWMUomlqQXFCclJ5rpFec mFtcmpeul5yfu4kR7L9n0jsYVzVYHGIU4GBU4uE1uiwaIMSaWFZcmXuIUYKDWUmEd5KIWIAQ b0piZVVqUX58UWlOavEhRmkOFiVxXhPvr/5CAumJJanZqakFqUUwWSYOTqkGRqPrt5auPCSr ptJvuKRjlt6DbYzvGM4qmC8yrLf7uoyl/Niya9sapW8+dVkp4dT42JxnoveqqlYLj+DjB1wi 9ivs8jpqz3nCqOlTUkXHjIsKXYu1/R5l/Wxa6bXhXFWpQnfQlLmxC57Z/Dz+OEtwfU/Qux71 z79ucX/1XLnm32OLlxyzChZcFVRiKc5INNRiLipOBACP/us12wEAAA== X-TM-AS-MML: No X-Spam-Note: CRM114 invocation failed X-Spam-Note: SpamAssassin invocation failed Cc: Russell King - ARM Linux , Arnd Bergmann , Chunsang Jeong , Kyungmin Park , Subash Patel , Minchan Kim , Hiroshi Doyu , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add some sanity checks and forbid mmaping of buffers into vma areas larger than allocated dma buffer. Signed-off-by: Marek Szyprowski --- arch/arm/mm/dma-mapping.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f906d5f..a2881c9 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -611,16 +611,22 @@ int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma, { int ret = -ENXIO; #ifdef CONFIG_MMU + unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; + unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; unsigned long pfn = dma_to_pfn(dev, dma_addr); + unsigned long off = vma->vm_pgoff; + vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) return ret; - ret = remap_pfn_range(vma, vma->vm_start, - pfn + vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot); + if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) { + ret = remap_pfn_range(vma, vma->vm_start, + pfn + off, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); + } #endif /* CONFIG_MMU */ return ret;