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: 10352 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B16B323F61 for ; Mon, 30 Jul 2012 08:30:29 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 6BFABA185BF for ; Mon, 30 Jul 2012 08:30:29 +0000 (UTC) Received: by yhpp61 with SMTP id p61so4450898yhp.11 for ; Mon, 30 Jul 2012 01:30:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:x-brightmail-tracker:x-tm-as-mml :cc:subject:x-beenthere:x-mailman-version:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:sender :errors-to:x-gm-message-state; bh=nG11uSTaEQSvK/adhxMwf4e5MLMyf8MuaCkCSsOjxdk=; b=e66FFcevAm/NKlHgYThsmr47WC5y3m1jdZ6Cv3tQjZuXtvXQDR3qib5Z9vYzezAYKJ Yqs/U/bUYYzGpDbk1U4GG9yfM6ityHJa6qzAZjGFIOVoOLzs+QLvKmXDZ2ZldZYXqoqI U73CEo/xiIzt5cjBTLaMl3J2bMh/FHjfmyGHHTT0CDnoSJ5uU8UO9DHXM7OAKyyDg55N O+4kW/DgoArjrUDFVrUxwMvJ/ib438Qg0fxeIX6Y4DggR/AVGuMYSgCAjD3IX21YRVJk cU9SovHFSNCCQGPHXTdoU4dM1Y4+yvhDCRatJEKuevyFWs/6rS8M+4TH+BsznnVUaPmB /SOQ== Received: by 10.42.54.133 with SMTP id r5mr6339645icg.9.1343637028562; Mon, 30 Jul 2012 01:30:28 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.87.40 with SMTP id u8csp76641igz; Mon, 30 Jul 2012 01:30:27 -0700 (PDT) Received: by 10.180.81.193 with SMTP id c1mr40622119wiy.12.1343637027167; Mon, 30 Jul 2012 01:30:27 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id dp1si14336989wib.9.2012.07.30.01.30.25; Mon, 30 Jul 2012 01:30:27 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SvlMu-0006lB-1J; Mon, 30 Jul 2012 08:30:24 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SvlMr-0006l3-UX for linaro-mm-sig@lists.linaro.org; Mon, 30 Jul 2012 08:30:22 +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 <0M7Y00JLJSXGDOT0@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Mon, 30 Jul 2012 17:30:07 +0900 (KST) X-AuditID: cbfee61b-b7f566d000005c8a-4a-5016460f01a3 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 98.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 linaro-mm-sig@lists.linaro.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 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+NgFjrJJMWRmVeSWpSXmKPExsVy+t9jQV1+N7EAg4bt4hZfrjxkcmD0uP3v MXMAYxSXTUpqTmZZapG+XQJXRsNNtYJHXBVXnys1MJ7k6GLk5JAQMJGYM7+FFcIWk7hwbz1b FyMXh5DAdEaJdddusUM4a5kk/l3bzgxSxSZgKNH1tosNxBYR8JB4suIcWJxZ4DWTxI+L9SC2 sIC3xISLr8HiLAKqEvtv7GMEsXmB6v9M2MAIsU1e4un9PrYJjNwLGBlWMYqmFiQXFCel5xrp FSfmFpfmpesl5+duYgR78Jn0DsZVDRaHGAU4GJV4eI0uiwYIsSaWFVfmHmKU4GBWEuGdJCIW IMSbklhZlVqUH19UmpNafIhRmoNFSZzXxPurv5BAemJJanZqakFqEUyWiYNTqoGRU7Xruv+9 ynTbL9Z/dN58lnT45fzD9s2yJQ1FG3f8/i7JfUNQeqJ34rIrf8LtVJgt88wufY188Heq1Z9J jH97Hu5/onuF/U6dnkj626/yE87cUcj2/l1ot+9hwatVx96yLjTboNu1Zte/WbOs7Dd2ef7d 9+nJSp4bTOv0jx9xvVEUmrjyn6aoqRJLcUaioRZzUXEiAOKBNsncAQAA X-TM-AS-MML: No Cc: Russell King - ARM Linux , Arnd Bergmann , Kyungmin Park , Minchan Kim Subject: [Linaro-mm-sig] [PATCH] ARM: dma-mapping: add more sanity checks in arm_dma_mmap() X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQksVTc9Lt+L4Qm2OqVncUzsAKUbMB+0srcclevh6WAsrGgqCfDc4ky2ExWTGgzeY1NZMeBb 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;