]> Git Repo - linux.git/commit
mm: pagewalk: Fix race between unmap and page walker
authorSteven Price <[email protected]>
Fri, 2 Sep 2022 11:26:12 +0000 (12:26 +0100)
committerLinus Torvalds <[email protected]>
Sat, 3 Sep 2022 17:13:13 +0000 (10:13 -0700)
commit8782fb61cc848364e1e1599d76d3c9dd58a1cc06
tree6177e2fedcece02fbb40952e04946fbe6cabdd30
parentd895ec7938c431fe61a731939da76a6461bc6133
mm: pagewalk: Fix race between unmap and page walker

The mmap lock protects the page walker from changes to the page tables
during the walk.  However a read lock is insufficient to protect those
areas which don't have a VMA as munmap() detaches the VMAs before
downgrading to a read lock and actually tearing down PTEs/page tables.

For users of walk_page_range() the solution is to simply call pte_hole()
immediately without checking the actual page tables when a VMA is not
present. We now never call __walk_page_range() without a valid vma.

For walk_page_range_novma() the locking requirements are tightened to
require the mmap write lock to be taken, and then walking the pgd
directly with 'no_vma' set.

This in turn means that all page walkers either have a valid vma, or
it's that special 'novma' case for page table debugging.  As a result,
all the odd '(!walk->vma && !walk->no_vma)' tests can be removed.

Fixes: dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap")
Reported-by: Jann Horn <[email protected]>
Signed-off-by: Steven Price <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Thomas Hellström <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
arch/riscv/mm/pageattr.c
mm/pagewalk.c
mm/ptdump.c
This page took 0.056112 seconds and 4 git commands to generate.