Re: [PATCH 20/21] binder: reverse locking order in shrinker callback
From: Carlos Llamas
Date: Fri Dec 01 2023 - 02:42:19 EST
On Tue, Nov 07, 2023 at 09:08:46AM +0000, Alice Ryhl wrote:
> Carlos Llamas <cmllamas@xxxxxxxxxx> writes:
> This reverses the order so that __free_page is called before
> zap_page_range_single. Is that okay?
It is not OK. Userspace would still have access to the page between
__free_page() and zap_page() calls. This is bad, so thanks for catching
this.
> Another option would be to do something along these lines:
>
> page_to_free = page->page_ptr;
> page->page_ptr = NULL;
>
> [snip]
>
> mmap_read_unlock(mm);
> mmput_async(mm);
> __free_page(page_to_free);
>
> This way you wouldn't reverse the order. Also, you reduce the amount of
> time you spend holding the mmap read lock, since the page is freed
> without holding the lock.
>
Thanks, I've added this approach to v2.
--
Carlos Llamas