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);