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: 19992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2302641wru; Mon, 14 Nov 2022 10:41:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf7+X3iHoUuU0M0HK/YHxaKxmjqJYhUqKhqEiw3KserdkqB0BJ0s2Wv8I4ukOC+Mys/PGGLv X-Received: by 2002:aa7:cd99:0:b0:467:7508:89ca with SMTP id x25-20020aa7cd99000000b00467750889camr10133375edv.284.1668451284441; Mon, 14 Nov 2022 10:41:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668451284; cv=none; d=google.com; s=arc-20160816; b=pGoNtRFX8SOp8QDmr1SJH5jD0U4vhFKdgYPdZrkce2shgHqauCtB91Ut9m3sp2uanA Ep8S+eyHCeht+Btk9SYqSNoaFpIvvl8FjPhglhimvAvEHNIExoj9PoYJoyCOH+v+6Mkr D6p8U2Ogy1Gjx4ZDqLkcAOOeUpTFry2mtqfnX/6nWaV/xwNr8Scc5s85HKcKZK6tMgVe 4RlcyjTTYGoMPWU18v+xoP9aNfiCft1aD4r5/WpvH7WVCmp9TtN6bqLWZcP4LwwKVfj2 8oIFvovMjYd8/TOW8DnbZidIzNJNIJmYZoawBRJ2sM3wViD/IqvZWqZCm3305SdCuF1W y/QQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mK49qbwAAJCMPUbqcOWVx53HlXuM/VsmR0ItBntED1s=; b=Nq1Wg1JTCWxZI5lQk7yz6wjXNRfOuqW9JRhWiCo+I1rgCcdzMbCD/RQzCvogl8rR+i 9EcC8vUwY++ETlWFTepOYImpyG/xrW/StUA0ql8bMHDEsmF20cDw8ZNQXsh31cuQJj1P XrZIyXXbapCFZTjlw16njHWsWhZXcJ5h7K2x7Kg+KXdsuqCw9y69+xK+d5BxJQdfJ6ii HFlENXvgeNKaaXiQvh63Q2ayUAD+UnSqxj6AKoXEN3SoH3EU8qt+34imsfjf9Lja7Byb oJV31GMX0zCFxgJXV6RupFHNcG1xd3PlG6KaGqlfTdOCFQBn3IeVpLNSJv0QSRsz2Qnv 1I6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=swj2BFaQ; 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 u29-20020a50951d000000b0045cba2d74c3si7893859eda.541.2022.11.14.10.41.00; Mon, 14 Nov 2022 10:41:24 -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=swj2BFaQ; 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 S236951AbiKNSaT (ORCPT + 99 others); Mon, 14 Nov 2022 13:30:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236900AbiKNSaQ (ORCPT ); Mon, 14 Nov 2022 13:30:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E511A2BB35 for ; Mon, 14 Nov 2022 10:30:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 93279B8114B for ; Mon, 14 Nov 2022 18:30:06 +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 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?1749497973942335712?= X-GMAIL-MSGID: =?utf-8?q?1749497973942335712?= 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: 19988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2301978wru; Mon, 14 Nov 2022 10:40:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jQ+lu/PjH4Umz2e7EARil6LTrAwsmTYqkwzUlc44c/sBZyfQBoZy5gjgUlw8eaNC0EE4u X-Received: by 2002:a17:906:ae47:b0:78d:a871:737c with SMTP id lf7-20020a170906ae4700b0078da871737cmr11063318ejb.597.1668451208074; Mon, 14 Nov 2022 10:40:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668451208; cv=none; d=google.com; s=arc-20160816; b=qWqnNeLzYD5AABTBf0UAI3sOYKVTClEuDcSdDvZbyESYc0wGF2FzBpRxLUVyv4v6bd IOo674u6aTeru6IrNSDS2JPu0UziJONBCSCaAU2+bBSzBD3uOfUfKE+F2RlXngQyjqa7 2k7eBk0tQdxWT069SLeGaqvcbbC8IeBp/kKOocukb1HXyxB0TYKsREfH1EVOA8LNWkPm GzzxeHRU9zXy7WCHJHdrt0SpwuWw5Z/GNVE3tI3BuWTOroaE4zUl6pRStrTVOKirjYfU bYK74BwJmlZdrh4ERipRkgrxpYXetS11FBkS7vgVJAQfb+fbM0hPPQ/ekwPpTt2JEhg7 6OxQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9WKz7xa5HUQV2+mpfK1D0nsRtWfjAHQqAO3pOwayfIM=; b=F89E03MYp+Cph26P+VKUJYCW73cZWglNf5BEucGAcUsWuTu1eMhpJuevh6Wtr/ZgMG 5XkMiFsepRqtBRfdODTnWJRXlUv52c9gW0xirHIQzNHketPd9W4GJHO4nc2mXLTcrLO+ msKUXK9m3Qdte+zJfY16PJDCFzS6CgvM5E93FmamTVfP1WAGZcqGanCSYlCFB5ZyU77x d4bHmkAz3oBuaGPMYHwYhiBoXgSXC9FJ5RTFWebzacaHVOUe/tX5hrjONDVRlNemEBCk ZlJqfi6IIuumOMYKYsC/c62Kt39twlBzLyGvvCuXFK6rdkORM8sBQOTmUuuvPkueIvQU SsOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bY29PN+C; 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 g6-20020a056402320600b00461701dab0csi9351769eda.526.2022.11.14.10.39.43; Mon, 14 Nov 2022 10:40:08 -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=bY29PN+C; 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 S236900AbiKNSaW (ORCPT + 99 others); Mon, 14 Nov 2022 13:30:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236921AbiKNSaS (ORCPT ); Mon, 14 Nov 2022 13:30:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 729E625C47 for ; Mon, 14 Nov 2022 10:30:09 -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 ams.source.kernel.org (Postfix) with ESMTPS id 287A0B81158 for ; Mon, 14 Nov 2022 18:30:08 +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 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?1749497893781255174?= X-GMAIL-MSGID: =?utf-8?q?1749497893781255174?= 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);