Steven Price 8782fb61cc 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 <jannh@google.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-09-03 10:13:13 -07:00
..
2021-05-05 11:27:24 -07:00
2022-03-24 19:06:45 -07:00
2022-02-14 19:51:47 +01:00
2022-08-10 11:07:26 -07:00
2022-03-23 18:03:08 -07:00
2022-08-09 09:48:30 -07:00
2022-06-16 19:48:30 -07:00
2022-05-13 07:20:09 -07:00
2022-03-22 17:03:12 -07:00
2021-05-07 00:26:35 -07:00
2022-08-03 10:35:43 -07:00
2022-07-20 10:52:40 +01:00
2022-08-20 15:17:45 -07:00
2022-01-15 16:30:31 +02:00
2022-05-19 14:08:53 -07:00