From patchwork Mon Nov 14 17:55:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13042656 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 18DFAC4332F for ; Mon, 14 Nov 2022 17:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A70F8E0002; Mon, 14 Nov 2022 12:56:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8568A8E0001; Mon, 14 Nov 2022 12:56:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747C08E0002; Mon, 14 Nov 2022 12:56:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 657768E0001 for ; Mon, 14 Nov 2022 12:56:10 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 21E51120FBF for ; Mon, 14 Nov 2022 17:56:10 +0000 (UTC) X-FDA: 80132801700.01.A3752F7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 9E35614000D for ; Mon, 14 Nov 2022 17:56:08 +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 A1733612E8; Mon, 14 Nov 2022 17:56:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D419C433D6; Mon, 14 Nov 2022 17:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668448567; bh=N9oaQLJ/H/5suT+aYI93l3SxuUN2llh0pwyp5hPH95A=; h=From:To:Cc:Subject:Date:From; b=VPDdph3yhsmenWyM2ySHp62SlHm6XzYCbqg2d1pxHnfje1jIwGLxYu2frpBwU/nvv 5Ui5rUT3h+R+z09f7+AANzOfImaER/8vsVLX1byqpZTOiFwcaXJlApgw/NEQ4AKlV9 d0nieJodBldt1DrEzIqgF0TWy84OU+1TOUQKT3kxCVyYv/qLY9B16oALt6fCtTKftU K2sGh53Z/khfGI3Q1pDzQhtJ85pUAARMyQvRgsz6HRzmEKsZWxvGFcY0iMynrYOtlc LVAh3/+wJvhoQYCSylKolVcBiIguTtHib9pp5QliaSzQRTGTX7h9KPQzsBDhsEcLDN epRYjoRIEvLdQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/sysfs-schemes: skip stats update if the scheme directory is removed Date: Mon, 14 Nov 2022 17:55:52 +0000 Message-Id: <20221114175552.1951-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668448568; 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=ypth5obeTGXl2pYsNU9lcO2Sw0vFM1mPhyH5/wudj30=; b=boqHxVTl2HBJKWvH/srrLtGcxhCzkjOl4JGhFoKk9eednPpTTlA49w+XBYMI9wHYO0+6q+ xjl1vCOy9mBRKS7cYNHsWZ6vDUIyZmQfVyiDDI0lzOEDynIffj26+VzPxCPSzsDQMrrkth peNNhPwCaGeKK723vVytqTZuTFFWpx8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VPDdph3y; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668448568; a=rsa-sha256; cv=none; b=vXG8ojevyqmraObNittH2Eero54F2zF+b8lFrxnzcDZ8XIWGDXeGFV5zVls+b6A2vQqRDo mVnsMpwFxfjRI2iHJyOxSiE5KjQ7I1PgsnVXLHZmYLu5QGSoci7dAkIvqUJg3hxuX1emgV hqKQetXQVQZFxTHLtfpyjxtda9/NKH0= X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9E35614000D Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VPDdph3y; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: r3pdqo9pqzzu1kujstk8k1ic4yr35jtg X-HE-Tag: 1668448568-417453 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 update of the scheme's stats. Because the schemes stats 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: 0ac32b8affb5 ("mm/damon/sysfs: support DAMOS stats") Cc: # v5.18 Signed-off-by: SeongJae Park --- Note: There are DAMON code refactoring patches in mm-stable. As the refactoring changes the code that this fix is touching, while this fix is for v6.1 hotfix, this patch is based on the latest mainline, not the mm-unstable. In other words, this patch cannot cleanly applied on mm-unstable. You could get this patch based on latest mm-unstable via damon/next tree[1], though. [1] https://git.kernel.org/pub/scm/linux/kernel/git/sj/linux.git/tree/?h=damon/next mm/damon/sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 9f1219a67e3f..9701ef178a4d 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2339,6 +2339,10 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) damon_for_each_scheme(scheme, ctx) { struct damon_sysfs_stats *sysfs_stats; + /* user could removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + break; + sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats; sysfs_stats->nr_tried = scheme->stat.nr_tried; sysfs_stats->sz_tried = scheme->stat.sz_tried;