Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2807650rdb; Mon, 12 Feb 2024 18:36:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+i4Q980wpfHy4qUYxDukl/Mn9rXtmCWpVcVesiSJs5fzkE5mf/4c6pI/YAyo34oVQR4Jr+ezTeH0SIOLdysTjBijz+MsuXc7JO3ezWQ== X-Google-Smtp-Source: AGHT+IGveBJ9Od8wq3fykaNtvSuDGt6w+t3qK7U3CXBwfInBP/AdInLeSgYSwEk4ugyQgTJ6xsQV X-Received: by 2002:a17:907:7646:b0:a3c:e7d1:1e81 with SMTP id kj6-20020a170907764600b00a3ce7d11e81mr1029398ejc.17.1707791806012; Mon, 12 Feb 2024 18:36:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707791806; cv=pass; d=google.com; s=arc-20160816; b=FFUdA0US4e8Zs8Za3Mdz/63SgEsJuGirsHZ2lNnXLw8bAtsYpPnSKO6IcYzITG32u3 vbpSZoZFKEau6v3xlmjTUJetnhIalz3dc53unxM0csbaX4FT3DHcMqWLYVQNDRVwf4+q ocr9BrBiE+sV9C8OaocNh2wQIaYWQnt0Mi1H/7wg89qxEYwybMYRuYAibheDxC/l4mCn Nsj7B4PRbXQEjnv5kWZKMwxjkpBpuFF5QzUasur/WFm20JfLQzVQzVww5mX7kdo5CvOG yjPjfoaFtfDopEOparoHvi37OGl961fPWJ3iXCmEMCYqAI+BTn2Dm21pNQVwvxKp6r4r L9dw== 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=e+eMFvv4hcLS9U4i5COJIujzjq4US6jDjA9dPxbqs7U=; b=iWAcxlh4N8fli+h/mdL1YpcpopUF+jg3YzJoJMGUX0Bt14nQoBaeydXaehs1jNg8Lv S/gTAT+1YXCiu2zEPQ/Sp3slfAaGGAYLdC0+DHKfEQIX7Pc8zbmumuUoFhtryKrumh92 1o3JIKJkyjuEx8D7yx3+6x5BWNFTeoI14H71Yb3z8CRffYYsJyWzul91KuL+MfFjy/Lm KvsWZVMb8FjFb0iFaoHY+jsRx3+CMXzN7uUSwpZJB79jFuRFtemPv3k8tX5LIVeEVMCO 0xdrFfT1weLOdBAL80jj+hz/ISJnoa1rHIEECwVRhjOWbgrQGgiB6Zd4bYaYHEmz3wGy FYIQ==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVvGCW9fFY/jzKtvj7QjzmYSmjGrb2qOkvZrCpkf4E0fClbC9VRUjOFngueNZWgGiobAyG68LG0+PrZrNMLL3dTvDWOKdONJV6AHgaimg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d24-20020a1709064c5800b00a3bd851b912si765671ejw.505.2024.02.12.18.36.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:36:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62889-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62889-linux.lists.archive=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 BE2F51F22B00 for ; Tue, 13 Feb 2024 02:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE7D33D6D; Tue, 13 Feb 2024 02:36:37 +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 To: Andrew Morton Cc: SeongJae Park , 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit '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 --- 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); -- 2.39.2