mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dma-buf: system_heap: Reject private mappings in system_heap_mmap()
@ 2026-10-30 20:44 Chris Wiseman
  2026-10-31  1:44 ` T.J. Mercier
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Wiseman @ 2026-10-30 20:44 UTC (permalink / raw)
  To: Sumit Semwal, T.J. Mercier, John Stultz, Benjamin Gaignard,
	Brian Starkey, Christian König, Philipp Stanner
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel, stable,
	Chris Wiseman

When commit 381295758792 ("dma-buf: system_heap: Rework system heap to
use sgtables instead of pagelists") stopped using heap_helpers.c and
added a custom system_heap_mmap(), the check rejecting private mappings
was dropped.

Other exporters and buffer allocators reject private or copy-on-write
mappings in their mmap handlers: cma_heap_mmap() and mmap_udmabuf()
check that VM_SHARED or VM_MAYSHARE is set, and drm_gem_shmem_mmap()
and ttm_bo_mmap_obj() reject vma_is_cow_mapping(vma).

However, system_heap_mmap() omits this check and calls remap_pfn_range()
even when userspace requests MAP_PRIVATE with PROT_WRITE. As a result,
subsequent CPU writes to a MAP_PRIVATE mapping of a system heap buffer
fault into do_wp_page() -> wp_page_copy(), silently allocating private
anonymous copy-on-write pages whose writes never reach the underlying
system heap buffer pages.

Reject non-shared mappings in system_heap_mmap() with -EINVAL to match
cma_heap_mmap() and mmap_udmabuf().

Fixes: 381295758792 ("dma-buf: system_heap: Rework system heap to use sgtables instead of pagelists")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Wiseman <chriswiseman@google.com>
---
 drivers/dma-buf/heaps/system_heap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 1ef1bb3acbf1..f668dc8cb54a 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -235,6 +235,9 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
 	pgprot_t prot;
 	int i, ret;
 
+	if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
+		return -EINVAL;
+
 	prot = vma->vm_page_prot;
 	if (cc_shared_buffer(buffer))
 		prot = pgprot_decrypted(prot);
-- 
2.56.0.317.g454f8302e1-goog

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-31  1:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 20:44 [PATCH] dma-buf: system_heap: Reject private mappings in system_heap_mmap() Chris Wiseman
2026-10-31  1:44 ` T.J. Mercier

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®