From patchwork Mon Nov 14 18:29:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13042673 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 A38BCC4332F for ; Mon, 14 Nov 2022 18:30:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D8476B008A; Mon, 14 Nov 2022 13:30:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 189716B0092; Mon, 14 Nov 2022 13:30:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 002A86B0093; Mon, 14 Nov 2022 13:30:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E51776B008A for ; Mon, 14 Nov 2022 13:30:07 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 279CD1606D6 for ; Mon, 14 Nov 2022 18:30:07 +0000 (UTC) X-FDA: 80132887254.06.B17096D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id A64B4C0014 for ; Mon, 14 Nov 2022 18:30:06 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C241361342; Mon, 14 Nov 2022 18:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3E15C433C1; Mon, 14 Nov 2022 18:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668450605; bh=xilSGlQYchsVmmKikIJMaS8XjvWaQ2LB9bIwb65/qKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=swj2BFaQreATJBLs249o+BEvmHBNmuMldNlErlB/B8b9dA22U3sLrY9JShtl3euSQ LUc6YwbdvRPS2ozuIqEQEBnl0d69Is6VtnYjjY9at5mu9FXSttoIGplB/W7oT1oETx Bg5vWylJKHenAihciGdnpQLmqsR40s7x4mCjxqZzarjbfJAhtbKOh3HvWpLRiufxuf swEFNl8tFd4BuigWfcY2gMP5XJhOtmtc1aftM+cJkC2hGYAE6ag8mqW8UZW3eWp4cW 08HZe+AKn82IERaTJkXuoH6QLoQHIl9gbSUgUOtkzK/ZDCz5xXKMUIZZvT6toGxT7K rIhOCkkEEzaKA== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: skip tried regions update if the scheme directory has removed Date: Mon, 14 Nov 2022 18:29:53 +0000 Message-Id: <20221114182954.4745-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221114182954.4745-1-sj@kernel.org> References: <20221114182954.4745-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668450606; 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:in-reply-to:references:references:dkim-signature; bh=mK49qbwAAJCMPUbqcOWVx53HlXuM/VsmR0ItBntED1s=; b=sMabGSYV1QIiiUqEI5u9Bs2CgqCRcvDQJb7ThLMvjgXhptcGWVKFwUdQMw7fFjNr2IEL5v 8ADjGPikqR12Mnlur2IpbxFlUv3KwzN0taspxG65XBej8e7xJEIvbXeqTY9DZ32w1ervyn r+aD620c880b/IPRgby1F3bDj5kgfI0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=swj2BFaQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668450606; a=rsa-sha256; cv=none; b=AurEUQ6ZvJZa14GfSNd7yVQU4W0CAt2By4IcfkwsQ+khAnJY9t6ThyRkmFRXFRoC6emY0D Ocf8I+N7D2mAllXas+R5xsTV/F5gtMR3jwIL9oYKqPX23LaFtvi6br2V6dYywBkTin7OlV jJpAUyhZ87rJcFOSLWTxuEveXUDQbMA= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A64B4C0014 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=swj2BFaQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: qo9he5wwz8hyguf8jdc9i7nhmur3e5qe X-HE-Tag: 1668450606-789871 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: A DAMON sysfs interface user can start DAMON with a scheme, remove the sysfs directory for the scheme, and then ask updates of the scheme's tried regions. Because the schemes tried regions update logic doesn't aware of the situation, it results in an invalid memory access. Fix the bug by checking if the scheme sysfs directory exists. Fixes: 1322c8148dfe ("mm/damon/sysfs: implement DAMOS tried regions update command") # mm-unstable Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index a79aa32d3422..4df3c99983e8 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1231,6 +1231,11 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, break; schemes_idx++; } + + /* user could removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + return 0; + sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; region = damon_sysfs_scheme_region_alloc(r); list_add_tail(®ion->list, &sysfs_regions->regions_list); From patchwork Mon Nov 14 18:29:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13042674 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 D6AAAC43217 for ; Mon, 14 Nov 2022 18:30:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 274C66B0092; Mon, 14 Nov 2022 13:30:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24B9C6B0095; Mon, 14 Nov 2022 13:30:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ECE46B0096; Mon, 14 Nov 2022 13:30:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F0E7A6B0092 for ; Mon, 14 Nov 2022 13:30:08 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8EEE0160DA8 for ; Mon, 14 Nov 2022 18:30:08 +0000 (UTC) X-FDA: 80132887296.14.B6DD355 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 193EE1A000C for ; Mon, 14 Nov 2022 18:30:07 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5DD166133A; Mon, 14 Nov 2022 18:30:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FF7DC433D6; Mon, 14 Nov 2022 18:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668450606; bh=KjLeGyUJTbZpSiKhaAFgRkOpgkH4ndx+JjCuYdxHGcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bY29PN+CyQgg6/VdgLjSq/jugOiRFtHQw+Xxc1h2PxY+BLAsSfEJ7e2CBv4KzGmfy 9/aoiEiu5ZSpriSJuR0gSVUmS+zYRvGafuYYtqMPEQDS2NhqQ1kwYdncApO+p92FTX stqy0WYhQYHGIR+bGkXrE3FUPMGugEp+sWfx013Sj93aJjNN7z2YCazcoSLdPWMwYs QdyULgUxl+x46SDTihwnGa4I8eGqJGE7esekjFcM5kv73P444WCvBH9nP8vA/qDCO7 rNn+jHctDyZHC5FSnsfooLElEb7u553FDcpbSBpBYlKV87QumPpjh6nmUZjpp5/d6T jXDfBuLGLo+CQ== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: skip schemes regions clearing if the scheme directory has removed Date: Mon, 14 Nov 2022 18:29:54 +0000 Message-Id: <20221114182954.4745-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221114182954.4745-1-sj@kernel.org> References: <20221114182954.4745-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668450608; a=rsa-sha256; cv=none; b=bPPhTekL63/8OdxyEuFkCJ5EDHMh42EtHxAp2wYPKle9NETAoOuqxkPCW4/lroh18NJ32n IIi6kDdRQ7Wn3yGuvyu0HyWqVj5y5u5Si9MU6f9LpAPqnhoQHhv9FS8gw3T8ajoYjNCIcT mdKo1bXHNdSIS9F8Qf0i7uWcTS/e1eE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bY29PN+C; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 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=1668450608; 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:in-reply-to:references:references:dkim-signature; bh=9WKz7xa5HUQV2+mpfK1D0nsRtWfjAHQqAO3pOwayfIM=; b=LivEgUb2YKNfcVjte+5jtgUOcDyDjEDzBkifwZAZseRoPfJIEGgks/XyRZ5jwf1LA7Hj0I 5Wm+shltUZV+VDJz3oJSwbT30cuCd52PjCPrKiHcDd67eKNiMJazgR12FwXNyoF2BJJPHL WQMThsJgpDaRjPq1aFyf256UzSlMMOM= X-Rspamd-Queue-Id: 193EE1A000C X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bY29PN+C; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam06 X-Stat-Signature: g38a64r3zb6n7zgkh1byksjnzb8wajej X-HE-Tag: 1668450607-134882 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: A DAMON sysfs interface user can start DAMON with a scheme, remove the sysfs directory for the scheme, and then ask clearing of the scheme's tried regions. Because the schemes tried regions clearing logic doesn't aware of the situation, it results in an invalid memory access. Fix the bug by checking if the scheme sysfs directory exists. Fixes: bb9641eb3a3e ("mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command") # mm-unstable 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 4df3c99983e8..e6baf55d617d 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1260,6 +1260,10 @@ int damon_sysfs_schemes_clear_regions( damon_for_each_scheme(scheme, ctx) { struct damon_sysfs_scheme *sysfs_scheme; + /* user could removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + break; + sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions);