From patchwork Fri Dec 13 22:24:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22410 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f199.google.com (mail-ig0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AD2DC23FBA for ; Fri, 13 Dec 2013 22:27:20 +0000 (UTC) Received: by mail-ig0-f199.google.com with SMTP id hk11sf2336505igb.2 for ; Fri, 13 Dec 2013 14:27:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=XA8XD26St1pXzMqr5KVFIw+MzkQQM8/4oOp07FmB3z0=; b=i2SxKuhPN8D0sZ5mY+uoIuGny0k0Dg3ZpZl8ScKT/a15GcXa114I3BSmrNMCkrrY+u JPGak5tO1h6VoFIvifI3j0hXWSpThSUdWFEDqFEdAnnGVDd+89ZlFdfXaUaBEcY7XyEs X9Fm8fmx84DrIhgFVG7o6f/M1D9a3jOidnidKw9L0nEGvqyHVT3MqsaSRP1Fw8n80GOK rY/2QvYbColX8WhZhTdX9/ZD7rUR+BH6pVxcGbFgsITvr2P4wKa9JfXxq4vhM4Oc5jDt R3wHyFy3GQBY5Xccq8sY4DkIHcfQdrEpeceFHrfAxJ41olMGVo6PcDB548Dli0DLb/YF 9LiQ== X-Gm-Message-State: ALoCoQle0yYGlj2wrlZwgyusycDo9NIPzE4ilBn2U+CcENbN6bbqUc/tX18bEc5f5sa4JhSlOyOb X-Received: by 10.42.81.84 with SMTP id y20mr1722673ick.10.1386973640369; Fri, 13 Dec 2013 14:27:20 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.132.164 with SMTP id ov4ls1174947qeb.32.gmail; Fri, 13 Dec 2013 14:27:20 -0800 (PST) X-Received: by 10.221.3.200 with SMTP id nz8mr1098692vcb.67.1386973640238; Fri, 13 Dec 2013 14:27:20 -0800 (PST) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id e3si1194557vek.93.2013.12.13.14.27.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:20 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.52; Received: by mail-vb0-f52.google.com with SMTP id p5so1705420vbn.39 for ; Fri, 13 Dec 2013 14:27:20 -0800 (PST) X-Received: by 10.58.233.98 with SMTP id tv2mr2191128vec.11.1386973640172; Fri, 13 Dec 2013 14:27:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73533vcz; Fri, 13 Dec 2013 14:27:19 -0800 (PST) X-Received: by 10.68.164.131 with SMTP id yq3mr6143251pbb.56.1386973639456; Fri, 13 Dec 2013 14:27:19 -0800 (PST) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id zi8si2497717pac.185.2013.12.13.14.27.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id z10so3041413pdj.2 for ; Fri, 13 Dec 2013 14:27:19 -0800 (PST) X-Received: by 10.66.190.198 with SMTP id gs6mr6062811pac.49.1386973639089; Fri, 13 Dec 2013 14:27:19 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.27.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:18 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 045/115] gpu: ion: Fix bug in ion_system_heap map_user Date: Fri, 13 Dec 2013 14:24:19 -0800 Message-Id: <1386973529-4884-46-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin When the requested mmap length was not an integer number of chunks or the buffer, or if an offset was provided, a bug would cause extra or incorrect pages of the buffer to be mapped. Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_system_heap.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 02726a9..df08469 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -292,18 +292,27 @@ int ion_system_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer, { struct sg_table *table = buffer->priv_virt; unsigned long addr = vma->vm_start; - unsigned long offset = vma->vm_pgoff; + unsigned long offset = vma->vm_pgoff * PAGE_SIZE; struct scatterlist *sg; int i; for_each_sg(table->sgl, sg, table->nents, i) { - if (offset) { - offset--; + struct page *page = sg_page(sg); + unsigned long remainder = vma->vm_end - addr; + unsigned long len = sg_dma_len(sg); + + if (offset >= sg_dma_len(sg)) { + offset -= sg_dma_len(sg); continue; + } else if (offset) { + page += offset / PAGE_SIZE; + len = sg_dma_len(sg) - offset; + offset = 0; } - remap_pfn_range(vma, addr, page_to_pfn(sg_page(sg)), - sg_dma_len(sg), vma->vm_page_prot); - addr += sg_dma_len(sg); + len = min(len, remainder); + remap_pfn_range(vma, addr, page_to_pfn(page), len, + vma->vm_page_prot); + addr += len; if (addr >= vma->vm_end) return 0; }