Skip to content

Commit ce8f9fb

Browse files
thejhgregkh
authored andcommitted
comedi: Flush partial mappings in error case
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]>
1 parent 9365f0d commit ce8f9fb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/comedi/comedi_fops.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,18 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
24072407

24082408
start += PAGE_SIZE;
24092409
}
2410+
2411+
#ifdef CONFIG_MMU
2412+
/*
2413+
* Leaving behind a partial mapping of a buffer we're about to
2414+
* drop is unsafe, see remap_pfn_range_notrack().
2415+
* We need to zap the range here ourselves instead of relying
2416+
* on the automatic zapping in remap_pfn_range() because we call
2417+
* remap_pfn_range() in a loop.
2418+
*/
2419+
if (retval)
2420+
zap_vma_ptes(vma, vma->vm_start, size);
2421+
#endif
24102422
}
24112423

24122424
if (retval == 0) {

0 commit comments

Comments
 (0)