From: "Arve Hjønnevåg" <arve@android.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
"Arve Hjønnevåg" <arve@android.com>
Subject: [PATCH] Staging: android: binder: Fix use-after-free bug
Date: Thu, 8 Mar 2012 15:43:36 -0800 [thread overview]
Message-ID: <1331250216-20666-1-git-send-email-arve@android.com> (raw)
In-Reply-To: <20120306041015.GP23916@ZenIV.linux.org.uk>
binder_update_page_range could read freed memory if the vma of the
selected process was freed right before the check that the vma
belongs to the mm struct it just locked.
If the vm_mm pointer in that freed vma struct had also been rewritten
with a value that matched the locked mm struct, then the code would
proceed and possibly modify the freed vma.
Signed-off-by: Arve Hjønnevåg <arve@android.com>
---
drivers/staging/android/binder.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 4350425..be42bf2 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -288,6 +288,7 @@ struct binder_proc {
struct rb_root refs_by_node;
int pid;
struct vm_area_struct *vma;
+ struct mm_struct *vma_vm_mm;
struct task_struct *tsk;
struct files_struct *files;
struct hlist_node deferred_work_node;
@@ -633,7 +634,7 @@ 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) {
+ if (vma && mm != proc->vma_vm_mm) {
pr_err("binder: %d: vma mm and task mm mismatch\n",
proc->pid);
vma = NULL;
@@ -2776,6 +2777,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
(vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
(unsigned long)pgprot_val(vma->vm_page_prot));
proc->vma = NULL;
+ proc->vma_vm_mm = NULL;
binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
}
@@ -2858,6 +2860,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
barrier();
proc->files = get_files_struct(proc->tsk);
proc->vma = vma;
+ proc->vma_vm_mm = vma->vm_mm;
/*printk(KERN_INFO "binder_mmap: %d %lx-%lx maps %p\n",
proc->pid, vma->vm_start, vma->vm_end, proc->buffer);*/
--
1.7.7.3
prev parent reply other threads:[~2012-03-08 23:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 6:37 [patches] VM-related fixes Al Viro
2012-03-05 6:38 ` [PATCH 1/3] aout: move setup_arg_pages() prior to reading/mapping the binary Al Viro
2012-03-05 6:39 ` [PATCH 2/3] VM_GROWS{UP,DOWN} shouldn't be set on shmem VMAs Al Viro
2012-03-05 6:40 ` [PATCH 3/3] flush_tlb_range() needs ->page_table_lock when ->mmap_sem is not held Al Viro
2012-03-05 20:30 ` Linus Torvalds
2012-03-05 20:53 ` Al Viro
2012-03-09 21:06 ` Benjamin Herrenschmidt
2012-03-06 3:38 ` [patches] VM-related fixes Arve Hjønnevåg
2012-03-06 4:10 ` Al Viro
2012-03-06 5:25 ` Arve Hjønnevåg
2012-03-06 5:57 ` Al Viro
2012-03-06 6:36 ` Arve Hjønnevåg
2012-03-08 23:43 ` Arve Hjønnevåg [this message]
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=1331250216-20666-1-git-send-email-arve@android.com \
--to=arve@android.com \
--cc=gregkh@linuxfoundation.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox