android: binder: fix dangling pointer comparison
authorJann Horn <jannh@google.com>
Wed, 15 Jun 2016 22:45:33 +0000 (00:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 15 Aug 2016 14:59:23 +0000 (16:59 +0200)
If /dev/binder is opened and the opener process then e.g. calls execve,
proc->vma_vm_mm will still point to the location of the now-freed
mm_struct. If the process then calls ioctl(binder_fd, ...), the dangling
proc->vma_vm_mm pointer will be compared to current->mm.

Let the binder take a reference to the mm_struct to avoid this.

v2: use the right refcounter

Fixes: a906d6931f3c ("android: binder: Sanity check at binder ioctl")
Signed-off-by: Jann Horn <jannh@google.com>
Reviewed-by: Chen Feng <puck.chen@hisilicon.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder.c

index 16288e777ec3dfdb50db2b133dd44f7e0045d8ad..09fdb425e2f5c68ed07f159f9c4b3dfc37ce1721 100644 (file)
@@ -2962,6 +2962,7 @@ static int binder_open(struct inode *nodp, struct file *filp)
                return -ENOMEM;
        get_task_struct(current);
        proc->tsk = current;
+       atomic_inc(&current->mm->mm_count);
        proc->vma_vm_mm = current->mm;
        INIT_LIST_HEAD(&proc->todo);
        init_waitqueue_head(&proc->wait);
@@ -3167,6 +3168,7 @@ static void binder_deferred_release(struct binder_proc *proc)
                vfree(proc->buffer);
        }
 
+       mmdrop(proc->vma_vm_mm);
        put_task_struct(proc->tsk);
 
        binder_debug(BINDER_DEBUG_OPEN_CLOSE,