From: Joel Fernandes <joel@joelfernandes.org>
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Todd Kjos <tkjos@android.com>,
jannh@google.com, arve@android.com, christian@brauner.io,
devel@driverdev.osuosl.org, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org, maco@android.com, tkjos@google.com,
Hridya Valsaraju <hridya@google.com>
Subject: Re: [PATCH] binder: prevent UAF read in print_binder_transaction_log_entry()
Date: Wed, 9 Oct 2019 10:21:29 -0400 [thread overview]
Message-ID: <20191009142129.GD143258@google.com> (raw)
In-Reply-To: <20191009104011.rzfdvq7otkkj533m@wittgenstein>
On Wed, Oct 09, 2019 at 12:40:12PM +0200, Christian Brauner wrote:
> On Tue, Oct 08, 2019 at 02:05:16PM -0400, Joel Fernandes wrote:
> > On Tue, Oct 08, 2019 at 03:01:59PM +0200, Christian Brauner wrote:
> > > When a binder transaction is initiated on a binder device coming from a
> > > binderfs instance, a pointer to the name of the binder device is stashed
> > > in the binder_transaction_log_entry's context_name member. Later on it
> > > is used to print the name in print_binder_transaction_log_entry(). By
> > > the time print_binder_transaction_log_entry() accesses context_name
> > > binderfs_evict_inode() might have already freed the associated memory
> > > thereby causing a UAF. Do the simple thing and prevent this by copying
> > > the name of the binder device instead of stashing a pointer to it.
> > >
> > > Reported-by: Jann Horn <jannh@google.com>
> > > Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs")
> > > Link: https://lore.kernel.org/r/CAG48ez14Q0-F8LqsvcNbyR2o6gPW8SHXsm4u5jmD9MpsteM2Tw@mail.gmail.com
> > > Cc: Joel Fernandes <joel@joelfernandes.org>
> > > Cc: Todd Kjos <tkjos@android.com>
> > > Cc: Hridya Valsaraju <hridya@google.com>
> > > Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
> > > ---
> > > drivers/android/binder.c | 4 +++-
> > > drivers/android/binder_internal.h | 2 +-
> > > 2 files changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c
> > > index c0a491277aca..5b9ac2122e89 100644
> > > --- a/drivers/android/binder.c
> > > +++ b/drivers/android/binder.c
> > > @@ -57,6 +57,7 @@
> > > #include <linux/sched/signal.h>
> > > #include <linux/sched/mm.h>
> > > #include <linux/seq_file.h>
> > > +#include <linux/string.h>
> > > #include <linux/uaccess.h>
> > > #include <linux/pid_namespace.h>
> > > #include <linux/security.h>
> > > @@ -66,6 +67,7 @@
> > > #include <linux/task_work.h>
> > >
> > > #include <uapi/linux/android/binder.h>
> > > +#include <uapi/linux/android/binderfs.h>
> > >
> > > #include <asm/cacheflush.h>
> > >
> > > @@ -2876,7 +2878,7 @@ static void binder_transaction(struct binder_proc *proc,
> > > e->target_handle = tr->target.handle;
> > > e->data_size = tr->data_size;
> > > e->offsets_size = tr->offsets_size;
> > > - e->context_name = proc->context->name;
> > > + strscpy(e->context_name, proc->context->name, BINDERFS_MAX_NAME);
> >
> > Strictly speaking, proc-context->name can also be initialized for !BINDERFS
> > so the BINDERFS in the MAX_NAME macro is misleading. So probably there should
> > be a BINDER_MAX_NAME (and associated checks for whether non BINDERFS names
> > fit within the MAX.
>
> I know but I don't think it's worth special-casing non-binderfs devices.
> First, non-binderfs devices can only be created through a KCONFIG option
> determined at compile time. For stock Android the names are the same for
> all vendors afaik.
I am just talking about the name of weirdly named macro here.
> Second, BINDERFS_MAX_NAME is set to the maximum path name component
> length that nearly all filesystems support (256 chars). If you exceed
> that then you run afoul of a bunch of other assumptions already and will
> cause trouble.
Again, just talking about the name.
> Third, even if there is someone crazy and uses more than 256 chars for a
> non-binderfs device at KCONFIG time strscpy will do the right thing and
> truncate and you'd see a truncated binder device name. This doesn't seem
> to be a big deal for a debugfs interface.
Sure I never said the patch has a bug.
> Fourth, the check for non-binderfs devices technically has nothing to do
> with this patch. This patch should really just do the minimal thing and
> fix the UAF. Which it does.
Again, never said the patch is buggy.
> Fifth, I already tried to push for validation of non-binderfs binder
> devices a while back when I wrote binderfs and was told that it's not
> needed. Hrydia tried the same and we decided the same thing. So you get
> to be the next person to send a patch. :)
I don't follow why we are talking about non-binderfs validation. I am just
saying a memcpy of the name could have been avoided for regular binder
devices. But since Todd Acked it, I wont stand in the way..
> > One more thought, this can be made dependent on CONFIG_BINDERFS since regular
> > binder devices cannot be unregistered AFAICS and as Jann said, the problem is
> > BINDERFS specific. That way we avoid the memcpy for _every_ transaction.
> > These can be thundering when Android starts up.
>
> Unless Todd sees this as a real performance problem I'm weary to
> introduce additional checking and record a pointer for non-binderfs and
> a memcpy() for binderfs devices. :)
Ok.
> > (I secretly wish C strings could be refcounted to avoid exactly this issue,
> > that should not be hard to develop but I am not sure if it is worth it for
> > this problem :) - For one, it will avoid having to do the strcpy for _every_
> > transaction).
> >
> > Other than these nits, please add my tag on whichever is the final solution:
> >
> > Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
>
> Thanks for the review, Joel. :)
My duty!! ;-)
thanks,
- Joel
next prev parent reply other threads:[~2019-10-09 14:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-07 20:49 UAF read in print_binder_transaction_log_entry() on ANDROID_BINDERFS kernels Jann Horn
2019-10-07 21:04 ` Todd Kjos
2019-10-07 21:16 ` Hridya Valsaraju
2019-10-07 21:05 ` Christian Brauner
2019-10-08 13:01 ` [PATCH] binder: prevent UAF read in print_binder_transaction_log_entry() Christian Brauner
2019-10-08 17:18 ` Hridya Valsaraju
2019-10-08 18:05 ` Joel Fernandes
2019-10-09 10:40 ` Christian Brauner
2019-10-09 14:21 ` Joel Fernandes [this message]
2019-10-09 14:29 ` Christian Brauner
2019-10-09 14:55 ` Joel Fernandes
2019-10-09 15:10 ` Christian Brauner
2019-10-09 15:37 ` Joel Fernandes
2019-10-09 15:56 ` Todd Kjos
2019-10-08 18:52 ` Todd Kjos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191009142129.GD143258@google.com \
--to=joel@joelfernandes.org \
--cc=arve@android.com \
--cc=christian.brauner@ubuntu.com \
--cc=christian@brauner.io \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=hridya@google.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@android.com \
--cc=tkjos@android.com \
--cc=tkjos@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.