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: 19946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2281238wru; Mon, 14 Nov 2022 10:00:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xDFJ9yxV/MJCnxzZjYZNMv/LUhzzakcQD1vcmwpaosFtkcBpq+LbkOp5BT14WhX4X2ABB X-Received: by 2002:a17:90a:9a8f:b0:212:9625:c8e9 with SMTP id e15-20020a17090a9a8f00b002129625c8e9mr14792271pjp.128.1668448830623; Mon, 14 Nov 2022 10:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668448830; cv=none; d=google.com; s=arc-20160816; b=1JbSYzOf9udW4ZRXxvaTZcZpP38mKiMKonklTD7KpWyaXOjiURqg3hvmexvVZzwUDs ZSSowJREBuzxFMuOo2SE+DwADp2vseKk+RIzZRRGF/xO0meKiExg0A6X6lOPjcbwjvqb 9XX6WAM/sxIljRtyjU0h7UTlXOYQusZXOU7nIF6UhFavlL+yWpJm6wOvixw/qcjEVYjB oA5SPVgP1hPltouBem6xIAJUY+R85bcFaaZoglm4+eAjhpF5tKedwaVipMKPjgsW3XNW LbAmYzJq5iM1qF/62QqrzRsTThyNHNU6iuCDmmaAa3LIFSti7+2YJksPWjR+4KTnUmdB 6pjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ypth5obeTGXl2pYsNU9lcO2Sw0vFM1mPhyH5/wudj30=; b=FLG7YLq/5ehZe1e1aEeZCEr4I7wa9l2/IkM+90CdOUy8pWom0ikfehb0jbDeqle70w Ciitz5lLCfFQvfYJ4b+viwgCc/VIepp8cdMBOf0LvBKUtjrhOIUCt5F4Ekvcv+OTFcjx cYVifqqnQeBM062dD322d2GNlMQ0T6grojofsO+JKyOjZeGaD+bv98n2pUFWYzLAyK8c 2ZKlOD8Fj3fk/iOu+VUpc1UWCDtDo0sIpriGmAaYumGwxSuqBaC8QRnh/lL5JqjS5cVF 0F+ddwa4aBLmjD23npOL+PHwRv+5l8Fk8lISjoba9uDfkGWEKoKhQ0Yi8NjBQ/2TaX8b hlPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VPDdph3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a190-20020a6390c7000000b0046b043d221csi9993224pge.55.2022.11.14.10.00.16; Mon, 14 Nov 2022 10:00:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VPDdph3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237458AbiKNR4Z (ORCPT + 99 others); Mon, 14 Nov 2022 12:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237915AbiKNR4I (ORCPT ); Mon, 14 Nov 2022 12:56:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C7926491; Mon, 14 Nov 2022 09:56:08 -0800 (PST) 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 B025061330; 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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749495400973054472?= X-GMAIL-MSGID: =?utf-8?q?1749495400973054472?= 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;