[PATCH 10/11] rust_binder: access page data through `SysMemLocal`

From: Andreas Hindborg

Date: Fri Nov 20 2026 - 05:28:08 EST


The pages of a binder page range are `Page<RefCounted>` pages, which
dereference to `Page<Shared>`. Thus, their data can be accessed through
the safe `Page::with_page_as_sysmem_local()`.

Use the view in `ShrinkablePageRange::copy_from_user_slice()` and
`ShrinkablePageRange::fill_zero()`. This removes the reliance on the
safety requirements of `Page::copy_from_user_slice_raw()` and
`Page::fill_zero_raw()` in these functions.

`ShrinkablePageRange::read()` and `ShrinkablePageRange::write()` copy to
and from raw pointers, so they keep using the raw accessors.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
drivers/android/binder/page_range.rs | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index bddc4538745e..2d360c32202e 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -538,14 +538,12 @@ pub(crate) unsafe fn copy_from_user_slice(
offset: usize,
size: usize,
) -> Result {
- // SAFETY: `self.iterate` has the same safety requirements as `copy_from_user_slice`. The
- // pages of this range are `Page<RefCounted>` pages, and this driver never creates a
- // reference to their data, so no reference to the data that is written exists.
- unsafe {
- self.iterate(offset, size, |page, offset, to_copy| {
- page.copy_from_user_slice_raw(reader, offset, to_copy)
- })
- }
+ let copy = |page: &Page, offset: usize, to_copy: usize| {
+ page.with_page_as_sysmem_local(offset, to_copy, |view| reader.read_sysmem(view))
+ };
+
+ // SAFETY: `self.iterate` has the same safety requirements as `copy_from_user_slice`.
+ unsafe { self.iterate(offset, size, copy) }
}

/// Copy from this page range into kernel space.
@@ -605,14 +603,15 @@ pub(crate) unsafe fn write<T: ?Sized>(&self, offset: usize, obj: &T) -> Result {
///
/// All pages touched by this operation must be in use for the duration of this call.
pub(crate) unsafe fn fill_zero(&self, offset: usize, size: usize) -> Result {
- // SAFETY: `self.iterate` has the same safety requirements as `fill_zero`. The pages of
- // this range are `Page<RefCounted>` pages, and this driver never creates a reference to
- // their data, so no reference to the data that is written exists.
- unsafe {
- self.iterate(offset, size, |page, offset, len| {
- page.fill_zero_raw(offset, len)
+ let fill = |page: &Page, offset: usize, len: usize| {
+ page.with_page_as_sysmem_local(offset, len, |view| {
+ view.fill_zero();
+ Ok(())
})
- }
+ };
+
+ // SAFETY: `self.iterate` has the same safety requirements as `fill_zero`.
+ unsafe { self.iterate(offset, size, fill) }
}
}


--
2.54.0