Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

android: binder: fix lockdep check on clearing vma

When munmapping a vma, the mmap_lock can be degraded to a write before
calling close() on the file handle. The binder close() function calls
binder_alloc_set_vma() to clear the vma address, which now has a lock dep
check for writing on the mmap_lock. Change the lockdep check to ensure
the reading lock is held while clearing and keep the write check while
writing.

Link: https://lkml.kernel.org/r/20220627151857.2316964-1-Liam.Howlett@oracle.com
Fixes: 472a68df605b ("android: binder: stop saving a pointer to the VMA")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: syzbot+da54fa8d793ca89c741f@syzkaller.appspotmail.com
Acked-by: Todd Kjos <tkjos@google.com>
Cc: "Arve Hjønnevåg" <arve@android.com>
Cc: Christian Brauner (Microsoft) <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hridya Valsaraju <hridya@google.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Martijn Coenen <maco@android.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Liam Howlett and committed by
akpm
b0cab80e a43cfc87

+8 -1
+8 -1
drivers/android/binder_alloc.c
··· 315 315 { 316 316 unsigned long vm_start = 0; 317 317 318 + /* 319 + * Allow clearing the vma with holding just the read lock to allow 320 + * munmapping downgrade of the write lock before freeing and closing the 321 + * file using binder_alloc_vma_close(). 322 + */ 318 323 if (vma) { 319 324 vm_start = vma->vm_start; 320 325 alloc->vma_vm_mm = vma->vm_mm; 326 + mmap_assert_write_locked(alloc->vma_vm_mm); 327 + } else { 328 + mmap_assert_locked(alloc->vma_vm_mm); 321 329 } 322 330 323 - mmap_assert_write_locked(alloc->vma_vm_mm); 324 331 alloc->vma_addr = vm_start; 325 332 } 326 333