* [PATCH] rust_binder: check VMA bounds before calling zap_vma_range()
@ 2026-12-01 10:19 Alice Ryhl
2026-12-01 10:35 ` Ivan Tverdokhleb
2026-12-01 10:46 ` FUJITA Tomonori
0 siblings, 2 replies; 3+ messages in thread
From: Alice Ryhl @ 2026-12-01 10:19 UTC (permalink / raw)
To: Greg Kroah-Hartman, Carlos Llamas, FUJITA Tomonori, Ivan Tverdokhleb
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux, linux-kernel,
stable
If userspace partially unmaps the tail of a binder VMA, the shrinker
still finds the shortened VMA at `vma_addr` and passes an out-of-bounds
`user_page_addr` to zap_vma_range().
Currently this out-of-bounds operation leads to zap_vma_range() printing
a warning and doing nothing. However, this warning has a TODO to replace
it with a WARN_ONCE(), which must not be reachable from userspace.
Another patch series has been posted [1] to fix this TODO, thus, check
that the page falls within the vma before calling zap_vma_range().
Note that Binder doesn't really support remapping or punching holes in
its VMA, so we accept that pages in the VMA aren't reachable for removal
by the shrinker when this occurs. But we must still ensure that it
cannot be used to trigger a WARN_ON() or other bad behavior.
Reported-by: FUJITA Tomonori <tomo@flapping.org>
Closes: https://lore.kernel.org/r/20261201.110643.1613182710699989646.tomo@flapping.org
Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/rust-for-linux/20261130230914.739923-1-tomo@flapping.org/ [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
drivers/android/binder/page_range.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index b0c797523bc2..422ceff7e887 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -750,7 +750,9 @@ fn drop(self: Pin<&mut Self>) {
if let Some(vma) = check_vma(&vma_read, range_ptr) {
let user_page_addr = vma_addr + (page_index << PAGE_SHIFT);
- vma.zap_vma_range(user_page_addr, PAGE_SIZE);
+ if user_page_addr < vma.end() {
+ vma.zap_vma_range(user_page_addr, PAGE_SIZE);
+ }
}
drop(vma_read);
---
base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
change-id: 20261201-binder-vma-lookup-ce9d22eb3dd6
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rust_binder: check VMA bounds before calling zap_vma_range()
2026-12-01 10:19 [PATCH] rust_binder: check VMA bounds before calling zap_vma_range() Alice Ryhl
@ 2026-12-01 10:35 ` Ivan Tverdokhleb
2026-12-01 10:46 ` FUJITA Tomonori
1 sibling, 0 replies; 3+ messages in thread
From: Ivan Tverdokhleb @ 2026-12-01 10:35 UTC (permalink / raw)
To: Alice Ryhl
Cc: Greg Kroah-Hartman, Carlos Llamas, FUJITA Tomonori, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
rust-for-linux, linux-kernel, stable
Hi Alice,
I applied your patch on top of Fujita's warn_on_once series and build-tested
it for x86_64 with CONFIG_RUST=y and CONFIG_DEBUG_VM=y. It builds cleanly.
I also ran the rust_kernel_bug KUnit tests, and both subtests passed
(test_warn_on and test_warn_on_once).
I will send v4 for zap_vma_range() once both your patch and Fujita's series
land in linux-next.
Tested-by: Ivan Tverdokhleb <mbkchelofficialdev@gmail.com>
Thanks,
Ivan
вт, 1 дек. 2026 г. в 12:19, Alice Ryhl <aliceryhl@google.com>:
>
> If userspace partially unmaps the tail of a binder VMA, the shrinker
> still finds the shortened VMA at `vma_addr` and passes an out-of-bounds
> `user_page_addr` to zap_vma_range().
>
> Currently this out-of-bounds operation leads to zap_vma_range() printing
> a warning and doing nothing. However, this warning has a TODO to replace
> it with a WARN_ONCE(), which must not be reachable from userspace.
> Another patch series has been posted [1] to fix this TODO, thus, check
> that the page falls within the vma before calling zap_vma_range().
>
> Note that Binder doesn't really support remapping or punching holes in
> its VMA, so we accept that pages in the VMA aren't reachable for removal
> by the shrinker when this occurs. But we must still ensure that it
> cannot be used to trigger a WARN_ON() or other bad behavior.
>
> Reported-by: FUJITA Tomonori <tomo@flapping.org>
> Closes: https://lore.kernel.org/r/20261201.110643.1613182710699989646.tomo@flapping.org
> Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/rust-for-linux/20261130230914.739923-1-tomo@flapping.org/ [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> drivers/android/binder/page_range.rs | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
> index b0c797523bc2..422ceff7e887 100644
> --- a/drivers/android/binder/page_range.rs
> +++ b/drivers/android/binder/page_range.rs
> @@ -750,7 +750,9 @@ fn drop(self: Pin<&mut Self>) {
>
> if let Some(vma) = check_vma(&vma_read, range_ptr) {
> let user_page_addr = vma_addr + (page_index << PAGE_SHIFT);
> - vma.zap_vma_range(user_page_addr, PAGE_SIZE);
> + if user_page_addr < vma.end() {
> + vma.zap_vma_range(user_page_addr, PAGE_SIZE);
> + }
> }
>
> drop(vma_read);
>
> ---
> base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
> change-id: 20261201-binder-vma-lookup-ce9d22eb3dd6
>
> Best regards,
> --
> Alice Ryhl <aliceryhl@google.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rust_binder: check VMA bounds before calling zap_vma_range()
2026-12-01 10:19 [PATCH] rust_binder: check VMA bounds before calling zap_vma_range() Alice Ryhl
2026-12-01 10:35 ` Ivan Tverdokhleb
@ 2026-12-01 10:46 ` FUJITA Tomonori
1 sibling, 0 replies; 3+ messages in thread
From: FUJITA Tomonori @ 2026-12-01 10:46 UTC (permalink / raw)
To: aliceryhl
Cc: gregkh, cmllamas, tomo, mbkchelofficialdev, ojeda, boqun, gary,
bjorn3_gh, lossin, a.hindborg, tmgross, dakr, daniel.almeida,
tamird, acourbot, work, rust-for-linux, linux-kernel, stable
On Tue, 01 Dec 2026 10:19:27 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> If userspace partially unmaps the tail of a binder VMA, the shrinker
> still finds the shortened VMA at `vma_addr` and passes an out-of-bounds
> `user_page_addr` to zap_vma_range().
>
> Currently this out-of-bounds operation leads to zap_vma_range() printing
> a warning and doing nothing. However, this warning has a TODO to replace
zap_vma_range() doesn't print anything currently. It just returns.
I tested this with my reproducer, after changing the TODO in
zap_vma_range() to warn_on!(true). Without this patch, the warning is
triggered. With this patch, it is not.
Tested-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 10:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 10:19 [PATCH] rust_binder: check VMA bounds before calling zap_vma_range() Alice Ryhl
2026-12-01 10:35 ` Ivan Tverdokhleb
2026-12-01 10:46 ` FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®