Skip to contentSkip to conversation

mm/mmu_notifier: Fix mmget() assert in __mmu_interval_notifier_insert

PATCH Applied Jann Horn 2 participants 2 messages Sep 1, 2020

Subsystems (2)
lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 mm/mmu_notifier: Fix mmget() assert in __mmu_interval_notifier_insert

The comment talks about having to hold mmget() (which means mm_users), but the actual check is on mm_count (which would be mmgrab()).

Given that MMU notifiers are torn down in
mmput() -> __mmput() -> exit_mmap() -> mmu_notifier_release(), I believe that the comment is correct and the check should be on mm->mm_users. Fix it up accordingly.

Fixes 99cb252f5e68 ("mm/mmu_notifier: add an interval tree notifier")

---
Can someone please double-check this? I'm like 90% sure that I fixed this the right way around, but it'd be good if someone more familiar with mmu notifiers could confirm.

 mm/mmu_notifier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mmu_notifier.c +1 -1
index 4fc918163dd3..5654dd19addc 100644
@@ -913,7 +913,7 @@ static int __mmu_interval_notifier_insert(
 		return -EOVERFLOW;
 
 	/* Must call with a mmget() held */
-	if (WARN_ON(atomic_read(&mm->mm_count) <= 0))
+	if (WARN_ON(atomic_read(&mm->mm_users) <= 0))
 		return -EINVAL;
 
 	/* pairs with mmdrop in mmu_interval_notifier_remove() */

base-commit: 15bc20c6af4ceee97a1f90b43c0e386643c071b4

Signature · 1 line
2.28.0.402.g5ffc5be6b7-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jann Horn

The comment talks about having to hold mmget() (which means mm_users), but the actual check is on mm_count (which would be mmgrab()).

Given that MMU notifiers are torn down in
mmput() -> __mmput() -> exit_mmap() -> mmu_notifier_release(), I believe that the comment is correct and the check should be on mm->mm_users. Fix it up accordingly.

Quoted 6 lines
Fixes 99cb252f5e68 ("mm/mmu_notifier: add an interval tree notifier")

---
Can someone please double-check this? I'm like 90% sure that I fixed this the right way around, but it'd be good if someone more familiar with mmu notifiers could confirm.

Hmm.. I added the comment but copied the expression from older code.

The intent is certainly that the caller must have a mmget, this function must not race with __mmu_notifier_release() and the mmget is what prevents that.

Jason