Commit 7bbb015f authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Wen Zhiwei
Browse files

mm/damon/vaddr: protect vma traversal in __damon_va_thre_regions() with rcu read lock

stable inclusion
from stable-v6.6.54
commit b35a42bdaf18bd6f2e3137f7072567040ea5d81e
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAZ3K2

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b35a42bdaf18bd6f2e3137f7072567040ea5d81e

--------------------------------

commit fb497d6db7c19c797cbd694b52d1af87c4eebcc6 upstream.

Traversing VMAs of a given maple tree should be protected by rcu read
lock.  However, __damon_va_three_regions() is not doing the protection.
Hold the lock.

Link: https://lkml.kernel.org/r/20240905001204.1481-1-sj@kernel.org


Fixes: d0cf3dd4 ("damon: convert __damon_va_three_regions to use the VMA iterator")
Signed-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/b83651a0-5b24-4206-b860-cb54ffdf209b@roeck-us.net


Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent da133ba1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ static int __damon_va_three_regions(struct mm_struct *mm,
	 * If this is too slow, it can be optimised to examine the maple
	 * tree gaps.
	 */
	rcu_read_lock();
	for_each_vma(vmi, vma) {
		unsigned long gap;

@@ -146,6 +147,7 @@ static int __damon_va_three_regions(struct mm_struct *mm,
next:
		prev = vma;
	}
	rcu_read_unlock();

	if (!sz_range(&second_gap) || !sz_range(&first_gap))
		return -EINVAL;