Re: [PATCH 1/7] binder: fix alloc->vma_vm_mm null-ptr dereference

From: Carlos Llamas
Date: Tue Aug 30 2022 - 15:40:59 EST


On Tue, Aug 30, 2022 at 07:06:37PM +0000, Liam Howlett wrote:
> > diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
> > index 51f4e1c5cd01..9b1778c00610 100644
> > --- a/drivers/android/binder_alloc.c
> > +++ b/drivers/android/binder_alloc.c
> > @@ -322,7 +322,6 @@ static inline void binder_alloc_set_vma(struct binder_alloc *alloc,
> > */
> > if (vma) {
> > vm_start = vma->vm_start;
> > - alloc->vma_vm_mm = vma->vm_mm;
>
> Is this really the null pointer dereference? We check for vma above..?
>

Not here. The sequence leading to the null-ptr-deref happens when we try
to take alloc->vma_vm_mm->mmap_lock in binder_alloc_new_buf_locked() and
in binder_alloc_print_pages() without initializing alloc->vma_vm_mm
first (e.g. mmap() was never called). These sequences are described in
the commit message but basically they translate to mmap_read_lock(NULL)
calls.