diff mbox

[3/7] ashmem: Fix ASHMEM_SET_PROT_MASK.

Message ID 1324428595-9253-4-git-send-email-john.stultz@linaro.org
State Accepted
Headers show

Commit Message

John Stultz Dec. 21, 2011, 12:49 a.m. UTC
From: Arve Hjønnevåg <arve@android.com>

Change-Id: I1412cc9560de8c4feb1162fc30922f0e3362a476
Signed-off-by: Arve Hjønnevåg <arve@android.com>
CC: Brian Swetland <swetland@google.com>
CC: Colin Cross <ccross@android.com>
CC: Arve Hjønnevåg <arve@android.com>
CC: Dima Zavin <dima@android.com>
CC: Robert Love <rlove@google.com>
CC: Greg KH <greg@kroah.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/staging/android/ashmem.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
diff mbox

Patch

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;