Skip to content

Commit c237a70

Browse files
thejhWen Zhiwei
authored andcommitted
comedi: Flush partial mappings in error case
stable inclusion from stable-v6.6.64 commit 9b07fb464eb69a752406e78e62ab3a60bfa7b00d category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IBL4B6 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9b07fb464eb69a752406e78e62ab3a60bfa7b00d -------------------------------- commit ce8f9fb651fac95dd41f69afe54d935420b945bd upstream. 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 79a61cc3fc04 ("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]> Signed-off-by: Wen Zhiwei <[email protected]>
1 parent daffdb1 commit c237a70

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)