[PATCH 2/2] android: drivers: Avoid debugfs race in binder

From: John Stultz
Date: Wed Feb 10 2016 - 00:06:42 EST


From: Riley Andrews <riandrews@xxxxxxxxxxx>

If a /d/binder/proc/[pid] entry is kept open after linux has
torn down the associated process, binder_proc_show can deference
an invalid binder_proc that has been stashed in the debugfs
inode. Validate that the binder_proc ptr passed into binder_proc_show
has not been freed by looking for it within the global process list
whilst the global lock is held. If the ptr is not valid, print nothing.

Cc: Colin Cross <ccross@xxxxxxxxxxx>
Cc: Arve HjÃnnevÃg <arve@xxxxxxxxxxx>
Cc: Dmitry Shmidt <dimitrysh@xxxxxxxxxx>
Cc: Rom Lemarchand <romlem@xxxxxxxxxx>
Cc: Serban Constantinescu <serban.constantinescu@xxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: Android Kernel Team <kernel-team@xxxxxxxxxxx>
Signed-off-by: Dmitry Shmidt <dimitrysh@xxxxxxxxxx>
[jstultz: Minor commit message tweaks]
Signed-off-by: John Stultz <john.stultz@xxxxxxxxxx>
---
drivers/android/binder.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 1db3761..f0ce995 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -3600,13 +3600,24 @@ static int binder_transactions_show(struct seq_file *m, void *unused)

static int binder_proc_show(struct seq_file *m, void *unused)
{
+ struct binder_proc *itr;
struct binder_proc *proc = m->private;
int do_lock = !binder_debug_no_lock;
+ bool valid_proc = false;

if (do_lock)
binder_lock(__func__);
- seq_puts(m, "binder proc state:\n");
- print_binder_proc(m, proc, 1);
+
+ hlist_for_each_entry(itr, &binder_procs, proc_node) {
+ if (itr == proc) {
+ valid_proc = true;
+ break;
+ }
+ }
+ if (valid_proc) {
+ seq_puts(m, "binder proc state:\n");
+ print_binder_proc(m, proc, 1);
+ }
if (do_lock)
binder_unlock(__func__);
return 0;
--
1.9.1