From: "Arve Hjønnevåg" <arve@android.com>
To: linux-kernel@vger.kernel.org
Cc: "Al Viro" <viro@ZenIV.linux.org.uk>,
"Arve Hjønnevåg" <arve@android.com>,
"Greg Kroah-Hartman" <gregkh@suse.de>,
"Christopher Lais" <chris+android@zenthought.org>,
devel@driverdev.osuosl.org
Subject: [PATCH 1/2] Staging: android: binder: Add some error checks
Date: Fri, 20 Jan 2012 19:56:20 -0800 [thread overview]
Message-ID: <1327118181-3542-2-git-send-email-arve@android.com> (raw)
In-Reply-To: <1327118181-3542-1-git-send-email-arve@android.com>
- Add a mutex to protect against two processes mmapping the
same binder_proc.
- After locking mmap_sem, check that the vma we want to access
(still) points to the same mm_struct.
- Use proc->tsk instead of current to get the files struct since
this is where we get the rlimit from.
Signed-off-by: Arve Hjønnevåg <arve@android.com>
---
drivers/staging/android/binder.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 7491801..846b429 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -38,6 +38,7 @@
static DEFINE_MUTEX(binder_lock);
static DEFINE_MUTEX(binder_deferred_lock);
+static DEFINE_MUTEX(binder_mmap_lock);
static HLIST_HEAD(binder_procs);
static HLIST_HEAD(binder_deferred_list);
@@ -632,6 +633,11 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
if (mm) {
down_write(&mm->mmap_sem);
vma = proc->vma;
+ if (vma && mm != vma->vm_mm) {
+ pr_err("binder: %d: vma mm and task mm mismatch\n",
+ proc->pid);
+ vma = NULL;
+ }
}
if (allocate == 0)
@@ -2803,6 +2809,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
}
vma->vm_flags = (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE;
+ mutex_lock(&binder_mmap_lock);
if (proc->buffer) {
ret = -EBUSY;
failure_string = "already mapped";
@@ -2817,6 +2824,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
}
proc->buffer = area->addr;
proc->user_buffer_offset = vma->vm_start - (uintptr_t)proc->buffer;
+ mutex_unlock(&binder_mmap_lock);
#ifdef CONFIG_CPU_CACHE_VIPT
if (cache_is_vipt_aliasing()) {
@@ -2849,7 +2857,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
binder_insert_free_buffer(proc, buffer);
proc->free_async_space = proc->buffer_size / 2;
barrier();
- proc->files = get_files_struct(current);
+ proc->files = get_files_struct(proc->tsk);
proc->vma = vma;
/*printk(KERN_INFO "binder_mmap: %d %lx-%lx maps %p\n",
@@ -2860,10 +2868,12 @@ err_alloc_small_buf_failed:
kfree(proc->pages);
proc->pages = NULL;
err_alloc_pages_failed:
+ mutex_lock(&binder_mmap_lock);
vfree(proc->buffer);
proc->buffer = NULL;
err_get_vm_area_failed:
err_already_mapped:
+ mutex_unlock(&binder_mmap_lock);
err_bad_arg:
printk(KERN_ERR "binder_mmap: %d %lx-%lx %s failed %d\n",
proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
--
1.7.7.3
next prev parent reply other threads:[~2012-01-21 3:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-21 3:56 [PATCH 0/2] Binder bug fixes Arve Hjønnevåg
2012-01-21 3:56 ` Arve Hjønnevåg [this message]
2012-01-21 8:22 ` [PATCH 1/2] Staging: android: binder: Add some error checks Dan Carpenter
2012-01-31 18:52 ` Greg KH
2012-01-31 23:20 ` Arve Hjønnevåg
2012-02-01 6:53 ` Dan Carpenter
2012-02-01 22:29 ` Arve Hjønnevåg
2012-02-01 22:47 ` Greg KH
2012-02-01 23:29 ` [PATCH] Staging: android: binder: Fix crashes when sharing a binder file between processes Arve Hjønnevåg
2012-02-02 6:27 ` [PATCH 1/2] Staging: android: binder: Add some error checks Dan Carpenter
2012-01-21 3:56 ` [PATCH 2/2] Staging: android: binder: Don't call dump_stack in binder_vma_open Arve Hjønnevåg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327118181-3542-2-git-send-email-arve@android.com \
--to=arve@android.com \
--cc=chris+android@zenthought.org \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.