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: 13076895 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 D6EEFC4332F for ; Mon, 19 Dec 2022 17:18:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BB328E0002; Mon, 19 Dec 2022 12:18:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56B9F8E0001; Mon, 19 Dec 2022 12:18:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 433DC8E0002; Mon, 19 Dec 2022 12:18:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3377B8E0001 for ; Mon, 19 Dec 2022 12:18:18 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DD4471409E2 for ; Mon, 19 Dec 2022 17:18:17 +0000 (UTC) X-FDA: 80259714234.21.6E96CEB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 21B6110001C for ; Mon, 19 Dec 2022 17:18:15 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L7iuXB5Z; spf=pass (imf05.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671470296; 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:in-reply-to:references:references:dkim-signature; bh=028VkuVj4jjygfiyG/8RNBMLnORgopVRbdgD0WylOOo=; b=hM+xao56OEFNaclPV2SaP7Mw650zoBe9NhD0/ui+aYHLfTEBb/D8cnfZ0+2Y1phUIKkrqg ZaO3kDBYfNZO6/qw515PcVaINonmpg/8oeI6Otv0ZxEqbSqMkkrRCFm22FGBP8bDvET+Lk sKn+Py7aUaGnQXhj5oNB1w0JVQybIeQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L7iuXB5Z; spf=pass (imf05.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=1671470296; a=rsa-sha256; cv=none; b=zL5X/UmDO3BOWE7t9EsxpScyf8EwhOTzHY2Mc/yYrJnW3L7U+F6DjJDCi7uY51VmSyhTIf GOSihBP0ngbxC/8+YUDEKutgxB7EMmm81BVuMc04UBF5hDxcgR5XUlESW+i8nN5qxJYihy 4m6ZtS30Gg0UnUVFPvxtm6zkxqigKJA= 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 0FDE3610A0; Mon, 19 Dec 2022 17:18:15 +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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 21B6110001C X-Rspam-User: X-Stat-Signature: qrnbzco3ypfe5zjjc8byy7j5afr97c3h X-HE-Tag: 1671470295-919156 X-HE-Meta: U2FsdGVkX18iO2il/9KFx1N2AacvFFZi+V8TzFr4+cLypWptETY5qdMzuenZKEKZp/vK0UN5po+oMTu3jSmlL3r9VZZmigqT18zrYRwJFKHWwSG6mB8TykWFXSEJ+ffFpg6UqBJwgOkYaQZwxM2nSn+KtLxS7HOGQY/geW/tEARcurAWerd43CxoqZR3firMK6oXw5g47lvPaLUVHHkkJz3t176ItyOkLQ6BzfC5/We+c1YLspeLbtQhoxi9ZRDYYJyZo8gTRaZWvCklfav37dUjqmQFeFCltIKqBEi4KkkQLaMUDnITZLtHoVUG/eOpzlM0WD7dukiGAX3VXMHVV0tdPGNabLg5RDzaQV63lXgtna1DGgbDHrP+PVNTUVhbr/eva+zK6EWXkhPMzBV4PTSosyD1VlkU7dTTzmIo3diHvGpE5yl8bYHcpY5wq3L6dHnbIs9WM+XipDTb9N5F9cuv3Xq7lf6qU7Ao5kLT8nO0KbRjkROtmpVwKwJYFXzjhnEDOM2l1IK/glS+9KSMWO9GpOHTm9NDvUYaBGlfB9V1q30ylGLsrofKUaVfPJPFN9qrtgYWtrcYx6gz8JAeHDin/vC9TNoP/mmMDhOwVuaKXmSs92xeoVXRohPsjTx8zW1NHaXoc0eCUMHpy0skBN7cApAx9swv1OecWjaiydpRdHnQAC5uLJdoqVY2rM3P0hJKM0F2g5IBaoH/eTsA5sxbpnwxowCLSVb7oVIKHBQBh6U2oV4hB4sYY4XTZWECzgAV01piADvuorVurhYCg1SpW98qbWCeI4XncJ4BRYkzUA40ELu8Ihhysn1fACFST8TNB40NugCEw6tDMRmwvHzGMLh97j8DF+zQb+U7NX/nKdOqXNCKEK7N2Cg35Ed3rugIN8xpdmJviJfwmy1ADKXhQglJ+7SJaBCr6SyqYRDfbszngBNmY/8nF88LSK+6RQUjTbva991K6nGL8Nb wDY5+Rsp qgt6H+RISt/ChogX86QpPgDjXzIMPqA0BUgwZWwb4KzkPbX/15GtT20+pxw+xtdCf9sMX 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: 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: 13076896 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 6ECF8C10F1B for ; Mon, 19 Dec 2022 17:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0E338E0005; Mon, 19 Dec 2022 12:18:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBE9B8E0001; Mon, 19 Dec 2022 12:18:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B386E8E0005; Mon, 19 Dec 2022 12:18:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A11FF8E0001 for ; Mon, 19 Dec 2022 12:18:19 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 66E4B120B20 for ; Mon, 19 Dec 2022 17:18:19 +0000 (UTC) X-FDA: 80259714318.27.1DF81A1 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf30.hostedemail.com (Postfix) with ESMTP id 977148000C for ; Mon, 19 Dec 2022 17:18:17 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IOziWT8N; spf=pass (imf30.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=1671470297; a=rsa-sha256; cv=none; b=vk1/5BEz2E7b+l7RY65GPJCwDuU0eiYcbt+9nhWWk1mvr4Bp752M6b6YR4MVbj+64FbrL7 pFxwXi6MLGL88ODLLCG8KEX6+Kg/ZXlq016So9LNcgLZXPRZZL1guteySumc0d4sVA9FoY 6ylzeXKNWYRRLN9NEJlv5kROxGMP1Vg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IOziWT8N; spf=pass (imf30.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671470297; 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:in-reply-to:references:references:dkim-signature; bh=i+Pv9uAqtdoN/1P8MZyuIsAYhEFZfX5nyJz5lTOnO6M=; b=LoTbDeYAyPvwDhSLlT2WE9fJmCd226Y/sao4+Voxh4pBhzDifRkKVS0onByeiDmNFxhE8Z zukU5LSUBsL+haRaZjyqqiQwMJ2v81RJSlvADPGtf6v3caB229j4GARDzIPITTuMxVIl5J 8L1t4BLAJizO3tVlvepKPTUmrP9dunc= 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 266BBB80F2B; Mon, 19 Dec 2022 17:18:16 +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-Rspam-User: X-Rspamd-Queue-Id: 977148000C X-Rspamd-Server: rspam01 X-Stat-Signature: bbptnbnsihiisd1fybhr5gzpgsuwoixy X-HE-Tag: 1671470297-432722 X-HE-Meta: U2FsdGVkX1/WhZ2/cJYL+ewj2CIn/Eay0DMs8vWMf7AwOK3iy2hUlHYUm3x9DsBJsaPBptOzgTZB+OwP5jQjj+3tyAcM9RPofAyWvdi/qDW5BoqFh9F2s3X79qmDiJH3jH9wUUUqj+AsVYaIeBg5OEQk4A4EpG2M/Wb0YOUHioKVQZf2VlRVICFVZvOPkMYNEXofA5bd7/rlfX/83+eKKc6aHD5WlCLv2I1DPlNyeKQTczzK/g/VzcVSOMrr1Imr+CUUP9O9eFfPAHK/FB7A0D7ke85CGV8QWqm7jILtrKU3FepsLbE+zmRh4fBCNgsqZJdFxFH1bF+2hrpkwIJ8zOQmVDDZdOvvMf7LmBakpDp6+isRz7m1If/HJbF4MTEW8z3NlPYB+TW5yNC43cmAG6N+AnCplvYO5JPpRR7Z46jYg5Dgz6JWrKHGI1NIxN2GI7hIxGLDWxqldgqMyNR0r3xKBnQgmxSSTAwPZdTABpSGBsAtu5seiusk/8llzMn3fwmeRRIPFbSS4jO20im3NRrgyPYhLIDY+6b77BTwl3vTAvE9oYLvlxeSAVKh1G9NW/HtPctwP88zPyc+Wu/KTj7bvFLv7LiJHwiAiIfpBOx7McAar1nqwpdKRt7tC8BxwO41vdZHyU/OzWKxNjHZt0qanAgPZ6HPQ29710PvRLl3RuwoXnhEZp37vmuU8AckCYSQpwBCOYMdBwas08m4NY5wnIVcqpacFAh7Lsrv4l2/g469RNAOF0z+e/BeOkQc26YKkaM71XHdmAmMCYfjjdzJNWtz0feYI8UoARCesCHpLyLjbojD5kxu1xM2iR6lM/VJAW7c5yxW5SgzRZlCC93pjEemCXP/2Z9sMGMd5g5YSqFKBbvzcE6RitBUSbZo95AoBJTU0cLuSOqeSmVKeSsUH/BKOdsSrX3jf3DyskPNtSJiaD6lfnmicWXpqQLtHyDCyQtq1hZ7ICg7/1F L+JUEz6i AaKh7mXr3qPa8fK5LiNx3gJuIrsntTFpsTl1ETQcp1tROPrzS0Gx5lG6zLn9xESi4oeR6 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: 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,