[PATCH 0/2] comedi: honour VMA protections in comedi_mmap()

From: Chris Down

Date: Sun Nov 29 2026 - 14:33:45 EST


comedi_mmap() maps buffers that weren't allocated for DMA with
PAGE_SHARED, so the pages are writable no matter how they were mapped.
That means anyone who can open a comedi device read-only can map its
buffer with PROT_READ and overwrite the samples in it.

Patch 1 fixes that by passing vma->vm_page_prot to remap_pfn_range(),
as the DMA path already does through dma_mmap_coherent().

Patch 2 rejects MAP_PRIVATE mappings, which comedi_mmap() can't set up
properly anyway: a mapping of more than one page already fails with
-EINVAL, and a single page one ends up with a vm_pgoff that
comedi_vm_access() can't use.

Chris Down (2):
comedi: Prevent writes to the buffer through read-only mappings
comedi: Reject MAP_PRIVATE mappings of the buffer

drivers/comedi/comedi_fops.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)


base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
--
2.56.1