Commit 657b514
mm: lock_vma_under_rcu() must check vma->anon_vma under vma lock
lock_vma_under_rcu() tries to guarantee that __anon_vma_prepare() can't
be called in the VMA-locked page fault path by ensuring that
vma->anon_vma is set.
However, this check happens before the VMA is locked, which means a
concurrent move_vma() can concurrently call unlink_anon_vmas(), which
disassociates the VMA's anon_vma.
This means we can get UAF in the following scenario:
THREAD 1 THREAD 2
======== ========
<page fault>
lock_vma_under_rcu()
rcu_read_lock()
mas_walk()
check vma->anon_vma
mremap() syscall
move_vma()
vma_start_write()
unlink_anon_vmas()
<syscall end>
handle_mm_fault()
__handle_mm_fault()
handle_pte_fault()
do_pte_missing()
do_anonymous_page()
anon_vma_prepare()
__anon_vma_prepare()
find_mergeable_anon_vma()
mas_walk() [looks up VMA X]
munmap() syscall (deletes VMA X)
reusable_anon_vma() [called on freed VMA X]
This is a security bug if you can hit it, although an attacker would
have to win two races at once where the first race window is only a few
instructions wide.
This patch is based on some previous discussion with Linus Torvalds on
the security list.
Cc: stable@vger.kernel.org
Fixes: 5e31275 ("mm: add per-VMA lock and helper functions to control it")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent 0a8db05 commit 657b514
1 file changed
+16
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5393 | 5393 | | |
5394 | 5394 | | |
5395 | 5395 | | |
5396 | | - | |
5397 | | - | |
5398 | | - | |
5399 | | - | |
5400 | 5396 | | |
5401 | 5397 | | |
5402 | 5398 | | |
| 5399 | + | |
| 5400 | + | |
| 5401 | + | |
| 5402 | + | |
| 5403 | + | |
| 5404 | + | |
| 5405 | + | |
| 5406 | + | |
| 5407 | + | |
5403 | 5408 | | |
5404 | 5409 | | |
5405 | 5410 | | |
5406 | 5411 | | |
5407 | | - | |
5408 | | - | |
5409 | | - | |
5410 | | - | |
| 5412 | + | |
| 5413 | + | |
5411 | 5414 | | |
5412 | 5415 | | |
5413 | | - | |
5414 | | - | |
5415 | | - | |
5416 | | - | |
| 5416 | + | |
| 5417 | + | |
5417 | 5418 | | |
5418 | 5419 | | |
5419 | 5420 | | |
| |||
5425 | 5426 | | |
5426 | 5427 | | |
5427 | 5428 | | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
5428 | 5432 | | |
5429 | 5433 | | |
5430 | 5434 | | |
| |||
0 commit comments