From patchwork Wed Dec 21 00:49:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 5915 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 0975D23E03 for ; Wed, 21 Dec 2011 00:51:05 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id EDA2CA1829C for ; Wed, 21 Dec 2011 00:51:04 +0000 (UTC) Received: by mail-ey0-f180.google.com with SMTP id c11so4023605eaa.11 for ; Tue, 20 Dec 2011 16:51:04 -0800 (PST) Received: by 10.204.129.24 with SMTP id m24mr1539971bks.89.1324428664807; Tue, 20 Dec 2011 16:51:04 -0800 (PST) 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.205.82.144 with SMTP id ac16cs26539bkc; Tue, 20 Dec 2011 16:51:04 -0800 (PST) Received: by 10.68.192.74 with SMTP id he10mr7415270pbc.13.1324428662370; Tue, 20 Dec 2011 16:51:02 -0800 (PST) Received: from e2.ny.us.ibm.com (e2.ny.us.ibm.com. [32.97.182.142]) by mx.google.com with ESMTPS id j7si4166334pbd.18.2011.12.20.16.51.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Dec 2011 16:51:02 -0800 (PST) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.142 as permitted sender) client-ip=32.97.182.142; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.142 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e2.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Dec 2011 19:51:00 -0500 Received: from d01relay04.pok.ibm.com (9.56.227.236) by e2.ny.us.ibm.com (192.168.1.102) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Dec 2011 19:50:04 -0500 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBL0o3Nw289514; Tue, 20 Dec 2011 19:50:03 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBL0o22e010277; Tue, 20 Dec 2011 22:50:03 -0200 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pBL0o1iu010213; Tue, 20 Dec 2011 22:50:01 -0200 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 0B9D91E74FE; Tue, 20 Dec 2011 16:50:01 -0800 (PST) From: John Stultz To: Greg KH Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Brian Swetland , Colin Cross , Dima Zavin , Robert Love , Greg KH , John Stultz Subject: [PATCH 3/7] ashmem: Fix ASHMEM_SET_PROT_MASK. Date: Tue, 20 Dec 2011 16:49:50 -0800 Message-Id: <1324428595-9253-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1324428595-9253-1-git-send-email-john.stultz@linaro.org> References: <1324428595-9253-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 x-cbid: 11122100-5112-0000-0000-0000034947EE From: Arve Hjønnevåg Change-Id: I1412cc9560de8c4feb1162fc30922f0e3362a476 Signed-off-by: Arve Hjønnevåg CC: Brian Swetland CC: Colin Cross CC: Arve Hjønnevåg CC: Dima Zavin CC: Robert Love CC: Greg KH Signed-off-by: John Stultz --- drivers/staging/android/ashmem.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 6f1a0bb..0b923b0 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -236,6 +236,13 @@ out: return ret; } +static inline unsigned long +calc_vm_may_flags(unsigned long prot) +{ + return _calc_vm_trans(prot, PROT_READ, VM_MAYREAD ) | + _calc_vm_trans(prot, PROT_WRITE, VM_MAYWRITE) | + _calc_vm_trans(prot, PROT_EXEC, VM_MAYEXEC); +} static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) { @@ -251,10 +258,12 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) } /* requested protection bits must match our allowed protection mask */ - if (unlikely((vma->vm_flags & ~asma->prot_mask) & PROT_MASK)) { + if (unlikely((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask)) & + calc_vm_prot_bits(PROT_MASK))) { ret = -EPERM; goto out; } + vma->vm_flags &= ~calc_vm_may_flags(~asma->prot_mask); if (!asma->file) { char *name = ASHMEM_NAME_DEF;