Commit f3277cb
binder: fix UAF when releasing todo list
When releasing a thread todo list when tearing down
a binder_proc, the following race was possible which
could result in a use-after-free:
1. Thread 1: enter binder_release_work from binder_thread_release
2. Thread 2: binder_update_ref_for_handle() -> binder_dec_node_ilocked()
3. Thread 2: dec nodeA --> 0 (will free node)
4. Thread 1: ACQ inner_proc_lock
5. Thread 2: block on inner_proc_lock
6. Thread 1: dequeue work (BINDER_WORK_NODE, part of nodeA)
7. Thread 1: REL inner_proc_lock
8. Thread 2: ACQ inner_proc_lock
9. Thread 2: todo list cleanup, but work was already dequeued
10. Thread 2: free node
11. Thread 2: REL inner_proc_lock
12. Thread 1: deref w->type (UAF)
The problem was that for a BINDER_WORK_NODE, the binder_work element
must not be accessed after releasing the inner_proc_lock while
processing the todo list elements since another thread might be
handling a deref on the node containing the binder_work element
leading to the node being freed.
Signed-off-by: Todd Kjos <tkjos@google.com>
Link: https://lore.kernel.org/r/20201009232455.4054810-1-tkjos@google.com
Cc: <stable@vger.kernel.org> # 4.14, 4.19, 5.4, 5.8
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent 78eef5d commit f3277cb
1 file changed
Lines changed: 10 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | 888 | | |
910 | 889 | | |
911 | 890 | | |
| |||
4585 | 4564 | | |
4586 | 4565 | | |
4587 | 4566 | | |
| 4567 | + | |
4588 | 4568 | | |
4589 | 4569 | | |
4590 | | - | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
4591 | 4574 | | |
4592 | 4575 | | |
4593 | 4576 | | |
4594 | | - | |
| 4577 | + | |
4595 | 4578 | | |
4596 | 4579 | | |
4597 | 4580 | | |
| |||
4625 | 4608 | | |
4626 | 4609 | | |
4627 | 4610 | | |
| 4611 | + | |
| 4612 | + | |
4628 | 4613 | | |
4629 | 4614 | | |
4630 | | - | |
| 4615 | + | |
4631 | 4616 | | |
4632 | 4617 | | |
4633 | 4618 | | |
| |||
0 commit comments