public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Tiffany Yang <ynaffit@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Martijn Coenen" <maco@android.com>,
	"Joel Fernandes" <joel@joelfernandes.org>,
	"Christian Brauner" <brauner@kernel.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v3 1/2] binder: Refactor binder_node print synchronization
Date: Fri, 9 May 2025 08:57:17 +0000	[thread overview]
Message-ID: <aB3DbelD08I1hL3U@google.com> (raw)
In-Reply-To: <dbx8a57nrkod.fsf@ynaffit-andsys.c.googlers.com>

On Thu, May 08, 2025 at 07:01:38PM +0000, Tiffany Yang wrote:
> Alice Ryhl <aliceryhl@google.com> writes:
> > I don't buy this logic. Imagine the following scenario:
> >
> > 1. print_binder_proc is called, and we loop over proc->nodes.
> > 2. We call binder_inner_proc_unlock(node->proc).
> > 3. On another thread, binder_deferred_release() is called.
> > 4. The node is removed from proc->nodes and node->proc is set to NULL.
> > 5. Back in print_next_binder_node_ilocked(), we now call
> >    spin_lock(&binder_dead_nodes_lock) and return.
> > 6. In print_binder_proc(), we think that we hold the proc lock, but
> >    actually we hold the dead nodes lock instead. BOOM.
> >
> > What happens with the current code is that print_binder_proc() takes the
> > proc lock again after the node was removed from proc->nodes, and then it
> > exits the loop because rb_next(n) returns NULL when called on a node not
> > in any rb-tree.
> >
> > Alice
> 
> 
> Thanks for catching this!! I think this race could be solved by passing
> "proc" in as a parameter (NULL if iterating over the dead_nodes_list),
> and locking/unlocking based on that instead of node->proc. WDYT?

I believe that would work.

Alice

      reply	other threads:[~2025-05-09  8:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 21:10 [PATCH v3 1/2] binder: Refactor binder_node print synchronization Tiffany Y. Yang
2025-05-07 21:10 ` [PATCH v3 2/2] binder: Create safe versions of binder log files Tiffany Y. Yang
2025-05-07 23:27   ` Carlos Llamas
2025-05-08 12:27 ` [PATCH v3 1/2] binder: Refactor binder_node print synchronization Alice Ryhl
2025-05-08 19:01   ` Tiffany Yang
2025-05-09  8:57     ` Alice Ryhl [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=aB3DbelD08I1hL3U@google.com \
    --to=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=surenb@google.com \
    --cc=tkjos@android.com \
    --cc=ynaffit@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox