mm/damon/sysfs-schemes: handle schemes sysfs dir removal before commit_schemes_quota_goals
Message ID | 20240213023633.124928-1-sj@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp290512dyb; Mon, 12 Feb 2024 18:36:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUt1VoqD8JMzfjxvVcNM9QjxV6bvJ14+8AHbPBoTxQbI+RfgHE7F71dhQy0SugOqaVp7SbcCogVTD3POBKkOhL9LEEZqA== X-Google-Smtp-Source: AGHT+IHjWYtkvjxax+lSjmLeDUKYNxxEgkxJ1XvuJUyTIWIPHBriHrRUSLElg5MeirzNoE0qvnLx X-Received: by 2002:a17:906:40ca:b0:a35:e7a1:66ec with SMTP id a10-20020a17090640ca00b00a35e7a166ecmr5386248ejk.44.1707791815171; Mon, 12 Feb 2024 18:36:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707791815; cv=pass; d=google.com; s=arc-20160816; b=Ak3IBm7FfHVyASZINFH0XRe4SM2pOEJuL08IplWhWX8UVoGJBkHvKQQ4QyVCetGx60 7sVPplO+Ap9fm86GXAMvvbHfwbYPkyWGR+x5o3t+2yIzuW/7KfPvoehiD+KxZZdFiu9w akgDACgV5aSHdXq3MbNstdR2kHmrxvM/QAFQKvEIEY/mZeEwFdccpCExRWUKr4jhaxi2 ELw1dbcdZ58gM5TjOqDkBC6H1iWbaWCP9O3iVnWHLUGpV1wOR7sAqLzU6aJnP8vgB4vT jmUaaAPH+vJHtUE6/ykIooF29TV24vMsEjiPtWhzHiqTDNd9MeXDhCh7j77j8u5BDPy2 bDKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=cOHV6gM0QA9twoqix8icKM+oOGfhVFK9WPapSXLjU+0=; fh=5N/mEipSYwclhIba24fzrWwGuYr9IwE+AUerZX2Muzs=; b=SJMX+0NksatG2N8EvJUvkH4Nqqb3GroyDc0kFUNq+ekA0OLuvFpz7waqo6H/GpRjtL nXHfELT+yCsUXB5qlnNPKBgVkXJ3Mhl05EzthlFyK8Y2YCsw8yR6hRjIdYZoHb2yc2ta Ui9T7/vOx3Ke0UVlI2AXHHrGArPBHZRXAsq8XK99jhg+C0+W/VNS9F4CkIY0iX4b+INF dL7OQ44g7my+F6Du/lXOLr4uZvnwvVZGeR4yph5adYs3FoZGfSz/bovcBY+MN7db6AhW +ZkADJzu4ip1S+A03eoQuoikAn67Y8AFkqS9O1Oq6wVoj2Typ+DZLLFVUvZD+EJfLTpW B86w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r32NUe2K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXAVrIzwwNjZ3AJR4B43nST37zfKS34/GW3P7PRgSuFyd+Fnp2xEE2oPQvKbDqlUsg5yARnjJPrH8GMSbsFZRcLYr8xVQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id me12-20020a170906aecc00b00a3cb859b964si758765ejb.445.2024.02.12.18.36.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:36:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r32NUe2K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62889-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C63131F222E5 for <ouuuleilei@gmail.com>; Tue, 13 Feb 2024 02:36:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFE5763D5; Tue, 13 Feb 2024 02:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r32NUe2K" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1168580B; Tue, 13 Feb 2024 02:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707791797; cv=none; b=mqnimZcjz8ZAgMOS09HeroaahsD2CWlXmvx2nlVDkbJ9+YawahBNA3tZqgApRZPAFaRKaC61R5gzF4ZMQa7gEeZcZ9XGqCUTQiz1OQ13KqAVWxCPUTD4sZr8zj7ebNDdYb4dsf8Sq005X64cruZoOnAP+KOLdDiY6rM0yanS5FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707791797; c=relaxed/simple; bh=ygxAPrJD39xiH5jwd8YqQbKkzfX8Q2c/ABdDAusTi5o=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=LWuq9hL6hurhV9IjIrF3pYWzCkUYOu0cR9yGLCRacFuT/TPB8EcOz/AgudAywA5sK48GnfBdYLvV0WZZ4IEtQ4bFZ3Xh7W93eb7iLCwZfQgOq89KEOTb2UQk06p03wJbmMDvXVqVJ5HAqDGXjM8TIGKOsprMcVyitRGmoj05tSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r32NUe2K; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22E05C433C7; Tue, 13 Feb 2024 02:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707791796; bh=ygxAPrJD39xiH5jwd8YqQbKkzfX8Q2c/ABdDAusTi5o=; h=From:To:Cc:Subject:Date:From; b=r32NUe2KJbXXRTqUWRebFFRNobzLoFQHk54L4g7kNDtRvv+K2BmRfXejGcfXil1mr 7eBc/VFFj54p1Vh2F1wZ119U0a2zXANAqB8EfcWb+uhiJormnSSz5cFihFFHQoejMW b2xZJ7Z0mSDsJWQkUwvJchLsOyJ+Pgsj64J/sbpAFNWZCaKZGxC5l5A6rrEkc3YM+2 etT1zQT+IfF+zPCB1NEcE+QogeOfR8d0jYyiH5RTXaCfrwkH8Ofac0D2jxwqA9qqRD v4L1eFTcQz5uvaqOzg1svcEFTGAi9ypQKAv0jV8ZHnVyurDXTPRU5WPQgKA9mdjRS2 ey3spt/owX9FQ== From: SeongJae Park <sj@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/sysfs-schemes: handle schemes sysfs dir removal before commit_schemes_quota_goals Date: Mon, 12 Feb 2024 18:36:32 -0800 Message-Id: <20240213023633.124928-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790749510321295906 X-GMAIL-MSGID: 1790749510321295906 |
Series |
mm/damon/sysfs-schemes: handle schemes sysfs dir removal before commit_schemes_quota_goals
|
|
Commit Message
SeongJae Park
Feb. 13, 2024, 2:36 a.m. UTC
'commit_schemes_quota_goals' command handler,
damos_sysfs_set_quota_scores() assumes the number of schemes sysfs
directory will be same to the number of schemes of the DAMON context.
The assumption is wrong since users can remove schemes sysfs directories
while DAMON is running. In the case, illegal memory accesses can
happen. Fix it by checking the case.
Fixes: d91beaa505a0 ("mm/damon/sysfs-schemes: implement a command for scheme quota goals only commit")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 98c6e5376486..f6c7f43f06cc 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1905,6 +1905,10 @@ void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, damon_for_each_scheme(scheme, ctx) { struct damon_sysfs_scheme *sysfs_scheme; + /* user could have removed the scheme sysfs dir */ + if (i >= sysfs_schemes->nr) + break; + sysfs_scheme = sysfs_schemes->schemes_arr[i]; damos_sysfs_set_quota_score(sysfs_scheme->quotas->goals, &scheme->quota);