From patchwork Tue Feb 13 02:36:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13554422 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 95F02C4829E for ; Tue, 13 Feb 2024 02:36:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23B7D6B0071; Mon, 12 Feb 2024 21:36:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C3C56B007D; Mon, 12 Feb 2024 21:36:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08C2C6B0082; Mon, 12 Feb 2024 21:36:44 -0500 (EST) 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 E7DD46B0071 for ; Mon, 12 Feb 2024 21:36:43 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B3FBC402DD for ; Tue, 13 Feb 2024 02:36:43 +0000 (UTC) X-FDA: 81785217486.21.4483C9B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id B6F6A180021 for ; Tue, 13 Feb 2024 02:36:41 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r32NUe2K; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707791802; 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=cOHV6gM0QA9twoqix8icKM+oOGfhVFK9WPapSXLjU+0=; b=GTMdz39y9i/5QPyXZeHZxfPvWKzRk8+CVZDUnL6Iclsv7/g1VXddSf9gNeoZW+M5CvCQzO CKbavApIBT29azfe/3DOjfkniZK/DFXww9aq0gSVD/FKaRGbNT6dFDIey6cCfRPxD8bBT6 QudwblwZQMT1Bg4XPMifV99PotRigYw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r32NUe2K; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707791802; a=rsa-sha256; cv=none; b=BjC+MdsR/DYTK7d3GyWHOs2jrmsTMFKOISszZO6wMtT13QBgHqWaQgPNj7la0WedjxQ2qU s9o57kiLsUMzG3fVdhK+buc21vYoK63oNRp5J7btIJyrxGyNgCQlQfFHYFdueJOo7YPQP/ ZtpZBT1qqByZz/mDw9ON8h7YjGXcmiQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3E49CCE1673; Tue, 13 Feb 2024 02:36:37 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B6F6A180021 X-Stat-Signature: p9d47j6dhymomerwqs5e5uhwt3eqsz84 X-Rspam-User: X-HE-Tag: 1707791801-761694 X-HE-Meta: U2FsdGVkX1/LMeMYmNfpAHikXY4Q1xz+pkOMxEI/Gvrbaq1WI/0J/RwogmwMxRDDFm6ZmHtqy0Tm/7DlnSz0rZ5OlDR02J0jHSfV+yatBAH/kFRtoLMNtLI3NFHuKMouvICEz6n9nsKLPiFVAIp2mFnjdmpv+tlDNwzVTAvFdbyxvHE4ACyapXyTALAh/uShOrxOlsqHECv6XsVTuMMIjRGL0X5MjnJzMPEQVshQojifWXp6L5Q2pQOCZtxqnnLxeCzPyzpgdBT6wlP4V1swP3ZO8GvTlOc79h5o1JsVBv82aVlpqk8ssLIITHp5lUhZz1vp/X/9thp2B+t++zKV2yjdzO1gxojtWUcpJaLqq/SdGkSnHC3J+Rc5Vdv9caW4DNA81MEOARl9HIiBckfuS0M0m1oRlNPnRGoCSU02SsAQA8fvv6SZz0U7iojLR4uGs3164OUBb9FZ6M4tyrlFBLvyZBxMudmj29WV9xVunC7wazMw3SS3r5FYbvOGMxHLwCH2RV2LTgYJvhk9PMElj/6UvOxba/ZKO2on7Tt2ca41lOW0tCRkbryDg9quNAD+I9piI+PIiJ33EycoNYlnyfGJ9JlH8dfQEOdgbZxMWEf9uFCl9MSD8JHOK317Wlz+xCSs1AFsv8iXBEZorunp3t1Uowy9BDVHxPJlmjaArP2um3sQ1JU9OdAJPgsUVqwutKXtTL9rC9ep4YyNd9eIViBHbwwvrPats/SykpwgU03Yfilb4UleH8uCJoAKr8xM8VzUDTkLtgLaPFmqfSZ4ruqe62/8aTPf+xqdL2A1KQ9InN0XOHhVv8LZPQspSbb8E7byqu/BgIUElC8PhHddtAOqUsVoABIut9eR+v35uPet3CE2AOilWim98wwiLUmlS4kAiq7rvpbZb5TvAVd/V90a9CqIWzK8MwqDiTjQeVFbj835qCjXh+Lj54PTZndl0LwFZnopWcp3CHzDCK6 pXkyFJy5 TI9NfQOyC9IHIdv1kO9MT1wiqze2CSB2muvChu2BgplmjqbZ4ahttEu/tX259GmWPyOkk8bWMYPDrOuKGZ1FeqqlPJRh46NQ2Zya+cXgew3P8P+fcuRgY/8bNGrNZHvEml5gPu6Dpevlel9B7dPMnKh/XQLBmqmIR0+Kp42Q46el/sG3mzOwnnfHKGJFxyQfxyDgWg1OuBJ+VGq9kaMURFNsL4DD90DH68EW0SSQPYqOGPsDsyGkhZYkB32lNTjFHvpSoFN1KnDUcbYmtp43r4pivvQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: '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);