From patchwork Thu Sep 5 00:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13791535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BD76CD4F22 for ; Thu, 5 Sep 2024 00:12:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 040EA6B00AC; Wed, 4 Sep 2024 20:12:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0C4B6B010D; Wed, 4 Sep 2024 20:12:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAD336B011C; Wed, 4 Sep 2024 20:12:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BBBF76B00AC for ; Wed, 4 Sep 2024 20:12:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 73A621C5F9F for ; Thu, 5 Sep 2024 00:12:14 +0000 (UTC) X-FDA: 82528757388.01.C848EA0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id D42B8100011 for ; Thu, 5 Sep 2024 00:12:12 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nfpMKzG4; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725495084; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=96MU/SsaBF+BPIr6Qehc/iQzVOVcjas8tcOhGGn+uAY=; b=A59T4oDfxnRVTlwTI9UHJTsdoS2J6VfHX6/Nqy3XCm4UpTsw/wspke4SZCS/sOO9DTGiaa YMle484sd9N4iy+yNx1I/B6ELbNQmw3VCAPXVsY6C/tj/rEC8EMHeMQ4vKaUCRVxtPATIi JUJgR4UDqPGlVn1ynhgk58iW88FdYYs= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nfpMKzG4; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725495084; a=rsa-sha256; cv=none; b=BiOhMhqyxjnm4D/nplquGLoYO5MxUv2yQpxkkGTfatjRI+f6wgUGFzmJySEPyACHdmHhFD jlaGoKw9MT7h3s9pyadkC5msgkmZD2lwn0ln3WDcUi7wJAMxxoCnGr4FhWXvTtge2KT9Fv W6sDoHJlttWa8DOds7MUq1ry9OOdvHM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3B4F95C5798; Thu, 5 Sep 2024 00:12:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C7ECC4CEC2; Thu, 5 Sep 2024 00:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725495131; bh=ot9I2Ee5hZbVpoV8bGx/1aoSYYU+azevoKMQDnXh7Ak=; h=From:To:Cc:Subject:Date:From; b=nfpMKzG4pw/I6Fb28XLxgiaUe4liVbXrW/g+urZOZRvdfo7TWn24bfTKch833D9hu 3gYfSETVlMFI6LfHABbm7iKEP+R3+pZVxlYXaCPRIWTe1o7Vz1YmzUz/IQGuC2emOL uuF03bP0xbVEGHP8H6H84W/n1AjZqEJBOg19rPln4css8x4ZGyIyHr10ii56HH/3aJ iaaBG+jlIHVn2WUCc76jIozvAahtA69V93Uslurz1wGX1e/jpKmItcQCtAr0M99X5R e6dYAcqqqCeLAPYV6xxtT5TPjs/EF0nVqWVK6WviiZe4m30jJzqq60R//Fl+Lrmn9E g/qkw6gUKUOdg== From: SeongJae Park To: Andrew Morton Cc: "Liam R. Howlett" , "Matthew Wilcox (Oracle)" , "Liam R. Howlett" , David Hildenbrand , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guenter Roeck , SeongJae Park Subject: [PATCH] mm/damon/vaddr: protect vma traversal in __damon_va_thre_regions() with rcu read lock Date: Wed, 4 Sep 2024 17:12:04 -0700 Message-Id: <20240905001204.1481-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: D42B8100011 X-Stat-Signature: gt4qgusc6w7s1mastgxcias5ayu9r4ca X-HE-Tag: 1725495132-769417 X-HE-Meta: U2FsdGVkX1+yHEE1wnM9rxJf7yFgHqSsgPMVh4Uohc3myeVkerPIgkVNZYrYsg174TMfZaoxz51ZXMVsYxySLNJtWwzkICu2IaKZOUksvpQOXqK0kzpZdYZwNfv7s/H0oFc1wwo612ngP6PxhzrKIAV1zzTSF5oYDL3pC2qx+WVMNJkyEZNJMJiNChDbfttL0C9kw9izVPL+QYFzGm0OHSM3QkbUrulwLVFzJSVariQ22XYLzlZd1SraH948pWwMcqYz3Kqs+nfU39wRuo4egQtwBOEtvZaYhh21ucCWcOjsmU228O1gJV63IlSF8vLm2N/XxV9GrjsAm2QBqKPCK7HEVz6/Eh/GxaOLOpPgtNbsS8/av5aAKYszL+aWWnOs403hozLtKnHdoBSubeAFwQUTJpTJ1Kl4gx4ERiPL9Ea+lv4WRq3blDwxOjsgzMdWaIK/GICftDdodTK3PJNniqQno7zVSLwPG0ZgP9pxSvKQystEvJHwY/p3tUunNcok7EJ9nF2LRWk90D3hdEUK2idLofkaxLDAjVksgEeO8+0f1ot7c+gujYl5lJ/ZW1yuh2ClNgjDAfs5ukYk4mUgn7QtnF+yODIb1sCpPBthlSEVXTIPHTNyF5pxJbtdYM97oMgtl97fg/yz+Z16hDbLOOq/AjpEhztLd/Fh8YwOUIbkp1/ZgheWQiFRsNdVPO75DtxsQZpdtLwq2uJU23cUokyp6zFQ5A2yARnU4jnbiyhXfXEs0pzQ1U7pDrn4vYAfN/lfgzwoNuRX8vfUPnV0LFUvZ4xC+pLmuXUTe1lEpJHAiWrDJIk/QFILILpT0qZoLWipr4TXtSLEpAl4Eqv8EJcFRm119ACbODLm57GbEdGdXkf/y1R90l5wbWQrM3s3927VjLb5l8xtXfVT2zAluxwLWCEaPSChxDanK9yAiT1mgD8fGvAn5HvUZd2Cey0FCcjweuvGHWi0IQRG+Yb /dCSgR/9 oJR9JsJGVq8qxa/zFHUxuMSEFP6ARq0/ZNMmg0E2ZjLeOD6gkpQjW6WIGcBVJJwHHpdTWGxIdugbA/FkMdPZmlwb4Yhw7i+XjzPOCMTph4jrlXRpwVYNuxw2yQ8IFTzTtASDn5G395/tV38hYvdZaxQl1y+s2CeUeEgQvuVug6sALYIyKl94Ejr44I6/o+rwnXvc37ztcdTZ/RvhrYAv3fQTv5IF1TS+4UnmQAhMHsnzTFTJNPykNPthRB8maSgqrvFBYH2xDgy9pXXxU0vMuSSKNwP5O2gDoXk8vfzIanRGEp0GUZRELJbJhwZpdy5utu+R25mDvU6na5deEX8Zht+LTebofe0ZdX/GW//RZMUhPWLU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Liam R. Howlett" 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. Reported-by: Guenter Roeck Closes: https://lore.kernel.org/b83651a0-5b24-4206-b860-cb54ffdf209b@roeck-us.net Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator") Signed-off-by: Liam R. Howlett Tested-by: Guenter Roeck Signed-off-by: SeongJae Park --- mm/damon/vaddr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index b0e8b361891d..08cfd22b5249 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -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;