The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] comedi: honour VMA protections in comedi_mmap()
@ 2026-11-29 19:33 Chris Down
  2026-11-29 19:33 ` [PATCH 1/2] comedi: Prevent writes to the buffer through read-only mappings Chris Down
  2026-11-29 19:33 ` [PATCH 2/2] comedi: Reject MAP_PRIVATE mappings of the buffer Chris Down
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Down @ 2026-11-29 19:33 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten; +Cc: linux-kernel, Greg Kroah-Hartman

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


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

end of thread, other threads:[~2026-11-29 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 19:33 [PATCH 0/2] comedi: honour VMA protections in comedi_mmap() Chris Down
2026-11-29 19:33 ` [PATCH 1/2] comedi: Prevent writes to the buffer through read-only mappings Chris Down
2026-11-29 19:33 ` [PATCH 2/2] comedi: Reject MAP_PRIVATE mappings of the buffer Chris Down

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox