linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mmap_lock: Reset maple state on lock_vma_under_rcu() retry
@ 2025-11-11 21:56 Liam R. Howlett
  2025-11-11 22:18 ` Vlastimil Babka
  2025-11-12 15:06 ` Lorenzo Stoakes
  0 siblings, 2 replies; 19+ messages in thread
From: Liam R. Howlett @ 2025-11-11 21:56 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Suren Baghdasaryan, Lorenzo Stoakes,
	Vlastimil Babka, Shakeel Butt, Jann Horn, Liam R. Howlett,
	stable, syzbot+131f9eb2b5807573275c

The retry in lock_vma_under_rcu() drops the rcu read lock before
reacquiring the lock and trying again.  This may cause a use-after-free
if the maple node the maple state was using was freed.

The maple state is protected by the rcu read lock.  When the lock is
dropped, the state cannot be reused as it tracks pointers to objects
that may be freed during the time where the lock was not held.

Any time the rcu read lock is dropped, the maple state must be
invalidated.  Resetting the address and state to MA_START is the safest
course of action, which will result in the next operation starting from
the top of the tree.

Prior to commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU
lock on failure"), the rcu read lock was dropped and NULL was returned,
so the retry would not have happened.  However, now that the read lock
is dropped regardless of the return, we may use a freed maple tree node
cached in the maple state on retry.

Cc: Suren Baghdasaryan <surenb@google.com>
Cc: stable@vger.kernel.org
Fixes: 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on failure")
Reported-by: syzbot+131f9eb2b5807573275c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=131f9eb2b5807573275c
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 mm/mmap_lock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index 39f341caf32c0..f2532af6208c0 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -257,6 +257,7 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
 		if (PTR_ERR(vma) == -EAGAIN) {
 			count_vm_vma_lock_event(VMA_LOCK_MISS);
 			/* The area was replaced with another one */
+			mas_set(&mas, address);
 			goto retry;
 		}
 
-- 
2.47.2



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-11-21 16:53 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-11 21:56 [PATCH] mm/mmap_lock: Reset maple state on lock_vma_under_rcu() retry Liam R. Howlett
2025-11-11 22:18 ` Vlastimil Babka
2025-11-12  0:10   ` Suren Baghdasaryan
2025-11-12  0:19     ` Liam R. Howlett
2025-11-12  0:45       ` Suren Baghdasaryan
2025-11-12  2:18         ` Liam R. Howlett
2025-11-12 20:24           ` Andrew Morton
2025-11-12 15:06 ` Lorenzo Stoakes
2025-11-12 16:10   ` Liam R. Howlett
2025-11-13 15:15     ` Lorenzo Stoakes
2025-11-13  0:04   ` Matthew Wilcox
2025-11-13  1:27     ` Paul E. McKenney
2025-11-13 11:05       ` Lorenzo Stoakes
2025-11-21  9:08         ` Vlastimil Babka
2025-11-21 16:52           ` Paul E. McKenney
2025-11-13 10:45     ` Lorenzo Stoakes
2025-11-13 17:28       ` Liam R. Howlett
2025-11-14 11:51         ` Lorenzo Stoakes
2025-11-14 17:18           ` Liam R. Howlett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox