binder: fix proc->files use-after-free
authorTodd Kjos <tkjos@android.com>
Mon, 27 Nov 2017 17:32:33 +0000 (09:32 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 2 Jan 2018 19:31:15 +0000 (20:31 +0100)
commitd87f1bc7d15b89bd3bcf31020eb7f3b3cd6f84b5
tree0a0f1f5d54da4b55c41918d606c54f04ad1bbc56
parent6fae6de72ad44e98b5ae58a662d110c58594aad9
binder: fix proc->files use-after-free

commit 7f3dc0088b98533f17128058fac73cd8b2752ef1 upstream.

proc->files cleanup is initiated by binder_vma_close. Therefore
a reference on the binder_proc is not enough to prevent the
files_struct from being released while the binder_proc still has
a reference. This can lead to an attempt to dereference the
stale pointer obtained from proc->files prior to proc->files
cleanup. This has been seen once in task_get_unused_fd_flags()
when __alloc_fd() is called with a stale "files".

The fix is to protect proc->files with a mutex to prevent cleanup
while in use.

Signed-off-by: Todd Kjos <tkjos@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder.c