Skip to content

Commit

Permalink
comedi: Flush partial mappings in error case
Browse files Browse the repository at this point in the history
If some remap_pfn_range() calls succeeded before one failed, we still have
buffer pages mapped into the userspace page tables when we drop the buffer
reference with comedi_buf_map_put(bm). The userspace mappings are only
cleaned up later in the mmap error path.

Fix it by explicitly flushing all mappings in our VMA on the error path.

See commit 79a61cc ("mm: avoid leaving partial pfn mappings around in
error case").

Cc: [email protected]
Fixes: ed9eccb ("Staging: add comedi core")
Signed-off-by: Jann Horn <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
thejh authored and gregkh committed Nov 5, 2024
1 parent 9365f0d commit ce8f9fb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions drivers/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,18 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)

start += PAGE_SIZE;
}

#ifdef CONFIG_MMU
/*
* Leaving behind a partial mapping of a buffer we're about to
* drop is unsafe, see remap_pfn_range_notrack().
* We need to zap the range here ourselves instead of relying
* on the automatic zapping in remap_pfn_range() because we call
* remap_pfn_range() in a loop.
*/
if (retval)
zap_vma_ptes(vma, vma->vm_start, size);
#endif
}

if (retval == 0) {
Expand Down

0 comments on commit ce8f9fb

Please sign in to comment.