All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos Llamas <cmllamas@google.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	kernel-team@android.com, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] binder: fix UAF in binder_free_transaction()
Date: Thu, 25 Jun 2026 02:45:37 +0000	[thread overview]
Message-ID: <ajyWUfA5BLrlNo9A@google.com> (raw)
In-Reply-To: <CAH5fLghnFSB0KYHQ7T4LEnHcx+kLP0RavpQL2LSyO2MCjE4DeA@mail.gmail.com>

On Mon, Jun 22, 2026 at 09:55:29PM +0200, Alice Ryhl wrote:
> > --- a/drivers/android/binder.c
> > +++ b/drivers/android/binder.c
> > @@ -1658,10 +1658,19 @@ static void binder_txn_latency_free(struct binder_transaction *t)
> >
> >  static void binder_free_transaction(struct binder_transaction *t)
> >  {
> > +       struct binder_thread *target_thread;
> >         struct binder_proc *target_proc;
> >
> >         spin_lock(&t->lock);
> >         target_proc = t->to_proc;
> > +       target_thread = t->to_thread;
> > +       /*
> > +        * Pin target_thread to keep target_proc alive. Undelivered
> > +        * transactions with !target_thread are safe, as target_proc
> > +        * can only be the current context there.
> > +        */
> > +       if (target_thread)
> > +               atomic_inc(&target_thread->tmp_ref);
> 
> This is more complicated than the comment suggests, but I think it's
> correct. As far as I can tell, scenarios where to_thread is NULL but
> to_proc is not are also scenarios where the caller ensures that
> to_proc stays alive during this function call.

Right, transactions with !to_thread and a valid to_proc are undelivered,
and as such they can only reach this point from the to_proc's context.

> 
> It's unfortunate that there's no obvious better way of doing this. I'd
> like to just take a refcount on the process, but it's not atomic, and
> you can't take the proc lock protecting it because of lock inversion.

Bingo! I'm using the thread as a proxy because refactoring proc->tmp_ref
to be atomic would be a bigger and thus riskier change.

> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Thanks!

      reply	other threads:[~2026-06-25  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19 18:52 [PATCH v2 1/2] binder: fix UAF in binder_thread_release() Carlos Llamas
2026-06-19 18:52 ` [PATCH v2 2/2] binder: fix UAF in binder_free_transaction() Carlos Llamas
2026-06-22 19:55   ` Alice Ryhl
2026-06-25  2:45     ` Carlos Llamas [this message]

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=ajyWUfA5BLrlNo9A@google.com \
    --to=cmllamas@google.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tkjos@android.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.