From patchwork Mon Dec 19 17:18:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 34667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2524703wrn; Mon, 19 Dec 2022 09:41:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6VardviBy5Txfz0yuEhC5jOWA1ZfualWTJPXaiDmeLVTfOKWMJ7idzVoX8lYcK7kvBHBvE X-Received: by 2002:a17:906:d8a5:b0:7c1:6f86:eeb with SMTP id qc5-20020a170906d8a500b007c16f860eebmr29063987ejb.7.1671471717695; Mon, 19 Dec 2022 09:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671471717; cv=none; d=google.com; s=arc-20160816; b=OOR3+ibjiqoK6XsPQw44OnCty73nFHnMramk9mFQPyOGBoYKShC8szTAEZ3MMwB9OC ga7RDddu3pkOld3ySvrO7aZA6VoGmBPKAdqZUUmSPmoMQCfTQz0DFYIt5GLqo2D0ubs2 zDkVmiy4umtoLnWNJoL0ah6YnBCuW/mlSE/0BL2ND3OVGr0n7Tj6mnX/5E2C30UMeqE+ L4br1q2e8zoXlbIAjZnEZb5gNhVJ2x/lhZCXO9Xf+4dJduWe85VhuwjNpZa3Tw548y4S YloNEmsaEOPL/ybX/IXPjtLS31WM4LnbLV5kNiIQovYVI03c3gZqSo8fPNnX+QPDzAqp HqDw== 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=028VkuVj4jjygfiyG/8RNBMLnORgopVRbdgD0WylOOo=; b=biRnOyippvttmbtGGDDehzDXgq9AG3Kzaj6YlcPzY9Q4zONsGpTLaYOPoGMMUL7Nz7 l69llvcKu9J5VteCAHt014AZjzzF+ph5Dn9SB+2LfGoRq8+cjLfJG49Wkd9Qg/dZahc7 MjEFiAJqCK8jcrowZ6P1PLPC0rCZh560dwyuGnMK80b3FL+ZK974LhfdoZLUVU1kyHy2 4mIaF7nG0D9jCPb51wXbTUXIEKrc4nE4JtD7ACpp43Dh8vmuq613N2CY9XTBgbXByonQ 0gM3PphuQ8r4JnBZB765p3fU6pTIuJSljokEXC1GWS+kV2okhxGp0nDxbB5SSe1ZwklI Ce2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L7iuXB5Z; 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 hq41-20020a1709073f2900b007ae74740fa4si10786605ejc.275.2022.12.19.09.41.34; Mon, 19 Dec 2022 09:41:57 -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=L7iuXB5Z; 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 S232369AbiLSRSW (ORCPT + 99 others); Mon, 19 Dec 2022 12:18:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbiLSRSQ (ORCPT ); Mon, 19 Dec 2022 12:18:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB43913E15 for ; Mon, 19 Dec 2022 09:18:14 -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 579416108C for ; Mon, 19 Dec 2022 17:18:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 588B5C433F0; Mon, 19 Dec 2022 17:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671470293; bh=Az1DXboUgRl+YAMk48Zah7TQBLUIJ4ua1EMPirQ5/3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7iuXB5ZEm6O0EUjdxu5DQDi6cpCEpzeu3Zsa9iJyPi1H/rZSq/6M5VA7cUOv1WH8 NVdoiSN3kxcVWbmlgVaZARrAW6n7M3KikLiJxzQKSc8wJkL+dPjnJs0eHGv1VmJFep 4PejNW+g758e7hTjmRmXx/epWzJrVzgg9d3jH1rTSyByV7g1kCvlqvOJ3mtLtC+xwz 107NmX9Um9h8GKmqextgzKBM75180RfQ0OKBM7t17wNxns3jG9UT+l8hhtX7ss46GO L8UX0b7e/kkSZJHB/zhPcbEiNjGNKHGkL+ERT9H9Rww1MgZRTiQVat2VYr0EDmOc7g wRi4h5+o1tB7Q== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path Date: Mon, 19 Dec 2022 17:18:06 +0000 Message-Id: <20221219171807.55708-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219171807.55708-1-sj@kernel.org> References: <20221219171807.55708-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?1752665127624084687?= X-GMAIL-MSGID: =?utf-8?q?1752665127624084687?= Commit f36f860207efa ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable introduced 'damon_syfs_set_scheme_filters()', which does not free newly allocated filter when it fails setting memcg id for the filter. As a result, the memory for the filter leaks. Fix it by freeing the filter before returning the error. Coverity CID: 1530032 Fixes: f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 0501862534f2..5d3ac3107927 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1464,8 +1464,10 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, err = damon_sysfs_memcg_path_to_id( sysfs_filter->memcg_path, &filter->memcg_id); - if (err) + if (err) { + damos_destroy_filter(filter); return err; + } } damos_add_filter(scheme, filter); } From patchwork Mon Dec 19 17:18:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 34669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2525876wrn; Mon, 19 Dec 2022 09:44:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7555PYmogrtF/yApY+uUbCDl56uhnGU+yK+o5Dq4i3hq7S8uxHvkQoqihhV/6TaNkR3J+D X-Received: by 2002:a17:906:704d:b0:7b9:62ab:dc3f with SMTP id r13-20020a170906704d00b007b962abdc3fmr54188751ejj.1.1671471881547; Mon, 19 Dec 2022 09:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671471881; cv=none; d=google.com; s=arc-20160816; b=oZftWbNB/z6r8cjvPXltBVfRZqH4gIvziKZWlNgkGXyf6xp95UscgKGif/yQxhH126 PWH7Pjs4LOjfogiYokd/88WjB9HU2FUeNWxsQozzCEmmNoS+5BgAdqFpa+tRiEH09MJa Ji7CViNIqQC1szSBTX3CHSazDHPOicumpnSV81v2/5T+FPLFg2iJKCfNV2CMhB6bC3h2 rOaV56n+si0oAKwihsbyN1hcL0nbKBr+eWceMa2gn3759Z25eDgMh17jGxwTXNkwqFya WBycjrQnP1VHUcdvFvfpBfYGMWuInSk7HOw1DXfkNEO0W33Jn266/RyQDMxJJ0s48B3u T3fA== 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=i+Pv9uAqtdoN/1P8MZyuIsAYhEFZfX5nyJz5lTOnO6M=; b=cP02r587Dhx9Oqi6QHju+MnfPGHQTx7K85QMQr9YkWWayufJHCMk5c8YCsqtcY4Ab4 Hw64jroJu2DyM3bsuiH45tihcBKTyGKVCjUXfTBTRq9RXG4qOSHGLFr7wj7fdDWr/gC4 v7i+QyBI9yU1FzIAB8l4sle5sB5Q7HffIzcUv8fERuvkWk+Ygbl0IxEIgxNNSWJfi4ms qMiD5y5/TmGX9b+lswwaXgOVrrnAXkNLvFazHxFNYdreJXg0oELfS2CVgW/YSWV4S2Kw uPGkPicWqPmkAjiqK/StihPo+wuHyMG1RDVD6p3e9I429pEQOczBrXxaS/DNCYS4LiU0 slnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IOziWT8N; 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 sd19-20020a1709076e1300b007d8acbd5717si6929056ejc.439.2022.12.19.09.44.18; Mon, 19 Dec 2022 09:44:41 -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=IOziWT8N; 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 S232349AbiLSRS1 (ORCPT + 99 others); Mon, 19 Dec 2022 12:18:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232311AbiLSRSS (ORCPT ); Mon, 19 Dec 2022 12:18:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CD45B499 for ; Mon, 19 Dec 2022 09:18:15 -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 ED6806109E for ; Mon, 19 Dec 2022 17:18:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC991C433AF; Mon, 19 Dec 2022 17:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671470294; bh=DScbhf2qkPduKtfJPNLimXEH2D1WRTFQEhM+/Oib0wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOziWT8N2rcIsbd8XCtsN/2zVXLABdKcySmLCpBta5IIK1AbrIdh374l0ZaLtosiG gbnRriNLCXYfshbWV9jQ9HRSRkUHCayl/lrReaGA6EBOuaceR8TUmX33CKAfIyDNup HCMJ/FHq9vg3Ud3o5/2z1kJFMp+lTAGvj+P5FQidAawhTCRFJxaOSLPTDBzJ5ortF3 uYDWENSn9ijdKmTSM2dr1gfcb4YqXtXxWEg0OdbkHVwRbduwofspwvetzMa+K2H//I JeS5Ro7NCgsFRW+6xdPv+cFZ/WG1Bqh9tEMFD+AtcBLxPDJRFOHnPsguWYZsqIYRLS nUO3EeTmg9OWw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: Return an error for filter memcg path id lookup failure Date: Mon, 19 Dec 2022 17:18:07 +0000 Message-Id: <20221219171807.55708-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219171807.55708-1-sj@kernel.org> References: <20221219171807.55708-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?1752665299720601620?= X-GMAIL-MSGID: =?utf-8?q?1752665299720601620?= Commit f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable introduced damon_sysfs_memcg_path_to_id(), which returns non-error even if it didn't find the memcg of the given path. Caller could check the failure by seeing if the 'id' has really set or not, but it's unnecessarily complicated. Return an error for the case instead. Fixes: f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 5d3ac3107927..f0dabe3e2dc0 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1418,6 +1418,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id) { struct mem_cgroup *memcg; char *path; + bool found = false; if (!memcg_path) return -EINVAL; @@ -1433,12 +1434,13 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id) continue; if (damon_sysfs_memcg_path_eq(memcg, path, memcg_path)) { *id = mem_cgroup_id(memcg); + found = true; break; } } kfree(path); - return 0; + return found ? 0 : -EINVAL; } static int damon_sysfs_set_scheme_filters(struct damos *scheme,