Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5875002rwb; Mon, 14 Nov 2022 10:39:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yovEa2Ue/SIECzSUwAXSWnHW3sDKrY3bJJM2xXTvetYgfCq8DEeVb6OKcVHS+4FVMWeFp X-Received: by 2002:a17:906:fb96:b0:7ad:dcf7:c4f with SMTP id lr22-20020a170906fb9600b007addcf70c4fmr11233257ejb.631.1668451154506; Mon, 14 Nov 2022 10:39:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668451154; cv=none; d=google.com; s=arc-20160816; b=SSkEHK/YBqYOMkPVuJq0wtYW9mUC6/Nn0L+/ZbMe8hxsq5uM1SbXWeUuwFUQFby6RQ i2MMMcZyT5l2E5Wo8wKvHVgMpjEkg5H5o1aGUHnQAsV+maPY4t8g3h+oKfrQc0bSMsiw nht+8HleRYUt3ArZqFBOdk4je6g4zXKWEQSDmRCA2zTDMlH7Kmb8X2uKsWbSvKKXSLHy XagKtu7g0zzS9eSxuJ8OgtuAfmuv9liU5VG9ilRrhGCf2H/jYMBWLy5JGVIfUDYIsItH BZHM17npLlEA/Bih/T4RH965dKkGumx+OUt8kYvsdCL0R6JytWzHtq0i1pTnQ+4wewK/ u1Uw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk35-20020a1709077fa300b007ad9c8201e7si10278076ejc.93.2022.11.14.10.38.52; Mon, 14 Nov 2022 10:39:14 -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 + 88 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 Content-Transfer-Encoding: 8bit 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 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; -- 2.25.1