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>,
"Martijn Coenen" <maco@android.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Christian Brauner" <brauner@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
linux-kernel@vger.kernel.org, kernel-team@android.com,
"David Hildenbrand" <david@redhat.com>,
"Barry Song" <v-songbaohua@oppo.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: Re: [PATCH v6 2/9] binder: concurrent page installation
Date: Wed, 4 Dec 2024 13:39:33 +0000 [thread overview]
Message-ID: <Z1BblcGDBvcdRTsO@google.com> (raw)
In-Reply-To: <CAH5fLgjMZw+58Wh58QVX2hD14=r-XkbtduTSchUPO14cJAJAww@mail.gmail.com>
On Wed, Dec 04, 2024 at 10:59:19AM +0100, Alice Ryhl wrote:
> On Tue, Dec 3, 2024 at 10:55 PM Carlos Llamas <cmllamas@google.com> wrote:
> >
> > Allow multiple callers to install pages simultaneously by switching the
> > mmap_sem from write-mode to read-mode. Races to the same PTE are handled
> > using get_user_pages_remote() to retrieve the already installed page.
> > This method significantly reduces contention in the mmap semaphore.
> >
> > To ensure safety, vma_lookup() is used (instead of alloc->vma) to avoid
> > operating on an isolated VMA. In addition, zap_page_range_single() is
> > called under the alloc->mutex to avoid racing with the shrinker.
>
> How do you avoid racing with the shrinker? You don't hold the mutex
> when binder_install_single_page is called.
>
> E.g. consider this execution:
>
> 1. binder_alloc_new_buf finishes allocating the struct binder_buffer
> and unlocks the mutex.
By the time the mutex is released in binder_alloc_new_buf() all the
pages that will be used have been removed from the freelist and the
shrinker will have no access to them.
> 2. Shrinker starts running, locks the mutex, sets the page pointer to
> NULL and unlocks the lru spinlock. The mutex is still held.
> 3. binder_install_buffer_pages is called and since the page pointer is
> NULL, binder_install_single_page is called.
> 4. binder_install_single_page allocates a page and tries to
> vm_insert_page it. It gets an EBUSY error because the shrinker has not
> yet called zap_page_range_single.
> 5. binder_install_single_page looks up the page with
> get_user_pages_remote. The page is written back to the pages array.
> 6. The shrinker calls zap_page_range_single followed by
> binder_free_page(page_to_free).
> 7. The page has now been freed and zapped, but it's in the page array. UAF.
>
> Is there something I'm missing?
I think that would be the call to binder_lru_freelist_del().
next prev parent reply other threads:[~2024-12-04 13:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 21:54 [PATCH v6 0/9] binder: faster page installations Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 1/9] Revert "binder: switch alloc->mutex to spinlock_t" Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 2/9] binder: concurrent page installation Carlos Llamas
2024-12-04 9:59 ` Alice Ryhl
2024-12-04 13:39 ` Carlos Llamas [this message]
2024-12-04 14:05 ` Alice Ryhl
2024-12-03 21:54 ` [PATCH v6 3/9] binder: select correct nid for pages in LRU Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 4/9] binder: store shrinker metadata under page->private Carlos Llamas
2024-12-04 9:39 ` Alice Ryhl
2024-12-04 13:55 ` Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 5/9] binder: replace alloc->vma with alloc->mapped Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 6/9] binder: rename alloc->buffer to vm_start Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 7/9] binder: use per-vma lock in page installation Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 8/9] binder: propagate vm_insert_page() errors Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 9/9] binder: use per-vma lock in page reclaiming Carlos Llamas
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=Z1BblcGDBvcdRTsO@google.com \
--to=cmllamas@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=brauner@kernel.org \
--cc=david@redhat.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=v-songbaohua@oppo.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.