Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 79a61cc3fc04 ("mm: avoid leaving partial pfn mappings around in
error case").

Cc: stable@vger.kernel.org
Fixes: ed9eccbe8970 ("Staging: add comedi core")
Signed-off-by: Jann Horn <jannh@google.com>
Link: https://lore.kernel.org/r/20241017-comedi-tlb-v3-1-16b82f9372ce@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jann Horn and committed by
Greg Kroah-Hartman
ce8f9fb6 9365f0de

+12
+12
drivers/comedi/comedi_fops.c
··· 2407 2407 2408 2408 start += PAGE_SIZE; 2409 2409 } 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 2410 2422 } 2411 2423 2412 2424 if (retval == 0) {