mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] binder: forbid VMA splitting and mremap on binder mmap
@ 2026-09-19 21:36 Hui Peng
  0 siblings, 0 replies; only message in thread
From: Hui Peng @ 2026-09-19 21:36 UTC (permalink / raw)
  To: gregkh, arve, tkjos, brauner, cmllamas, aliceryhl; +Cc: linux-kernel

`binder_vm_ops` does not implement `.may_split` or `.mremap`, and
`binder_vma_close()` unconditionally calls
`binder_alloc_vma_close(&proc->alloc)` (which sets `alloc->vma = NULL`).

If userspace calls `munmap()` on a sub-range of the binder mapping (or
`mremap()` to move/split a sub-range), the VMA is split into two VMAs
sharing the same `binder_proc`, and `binder_vma_close()` runs on the
unmapped half and clears `alloc->vma = NULL` while the remaining VMA
stays mapped in the process's address space, desynchronizing
`alloc->vma` from the remaining VMA.

Implement `.may_split` and `.mremap` returning `-EINVAL` in
`binder_vm_ops` and check `vma->vm_start == proc->alloc.vm_start` in
`binder_vma_close()`.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>

---
 drivers/android/binder.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 8f2ef1bd539f..1c7218e599a1 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -6023,9 +6058,21 @@ static void binder_vma_close(struct vm_area_struct *vma)
 		     proc->pid, vma->vm_start, vma->vm_end,
 		     (vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
 		     (unsigned long)pgprot_val(vma->vm_page_prot));
+	if (vma->vm_start != proc->alloc.vm_start)
+		return;
 	binder_alloc_vma_close(&proc->alloc);
 }
 
+static int binder_may_split(struct vm_area_struct *vma, unsigned long addr)
+{
+	return -EINVAL;
+}
+
+static int binder_mremap(struct vm_area_struct *vma)
+{
+	return -EINVAL;
+}
+
 VISIBLE_IF_KUNIT vm_fault_t binder_vm_fault(struct vm_fault *vmf)
 {
 	return VM_FAULT_SIGBUS;
@@ -6035,6 +6082,8 @@ EXPORT_SYMBOL_IF_KUNIT(binder_vm_fault);
 static const struct vm_operations_struct binder_vm_ops = {
 	.open = binder_vma_open,
 	.close = binder_vma_close,
+	.may_split = binder_may_split,
+	.mremap = binder_mremap,
 	.fault = binder_vm_fault,
 };
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-19 21:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 21:36 [PATCH] binder: forbid VMA splitting and mremap on binder mmap Hui Peng

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®