From patchwork Fri Oct 25 06:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13850080 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 2CA42D116FC for ; Fri, 25 Oct 2024 06:18:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 271636B0082; Fri, 25 Oct 2024 02:18:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 221BF6B0083; Fri, 25 Oct 2024 02:18:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E9BD6B0085; Fri, 25 Oct 2024 02:18:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E4AC06B0082 for ; Fri, 25 Oct 2024 02:18:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6D7F51C4407 for ; Fri, 25 Oct 2024 06:18:29 +0000 (UTC) X-FDA: 82711120548.25.E03C001 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf13.hostedemail.com (Postfix) with ESMTP id 59EB62001E for ; Fri, 25 Oct 2024 06:18:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729837077; a=rsa-sha256; cv=none; b=DeGG6lv+TlT/SQDrmMF7uwPWy+hwdiBF3Kv1YFOKq2UxAdM0XQ4aUhn5aULbB//rGkYfys DsU32pOCv5Ij4mEbB35HbBx8i4Vg6a4bq+/MHJjMNOtmUiBQ4pxhFUEI1+N/GQnwF7PjAN vO3PvNMGYXPAmIgX2UyQ0z/l38pu5X0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729837077; 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:references; bh=/0F6985Yv8sPrDmrf3RptdSgitEBwdQ3/KBU6Rk1TBA=; b=yEzRzC+SBzbggNP8eAPAImsROjV902+F5zYHiCw1DvsqncvIJGkqE5m6fp65YXAi2nvLke DqJaAc2GQMUKFqBqvt9Ze8ZCm+r9ERcpJ4uZIlEHYYel8sSjz9AuNVaeLLC1uMTwIwbEak RsTxSFQ8STOKsDe28XRfOk2J719mi7A= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4XZXfC6bfmz4f3jkV for ; Fri, 25 Oct 2024 14:18:27 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 5272C1A0568 for ; Fri, 25 Oct 2024 14:18:40 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgCXy8cjOBtndSE+FA--.48420S2; Fri, 25 Oct 2024 14:18:40 +0800 (CST) From: Chen Ridong To: akpm@linux-foundation.org, david@fromorbit.com, zhengqi.arch@bytedance.com, roman.gushchin@linux.dev, muchun.song@linux.dev, anshuman.khandual@arm.com, vbabka@suse.cz, kirill@shutemov.name Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, chenridong@huawei.com, wangweiyang2@huawei.com Subject: [PATCH v3] mm: shrinker: avoid memleak in alloc_shrinker_info Date: Fri, 25 Oct 2024 06:09:42 +0000 Message-Id: <20241025060942.1049263-1-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCXy8cjOBtndSE+FA--.48420S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uF13Cr4rur4Dtr4UGr17Wrg_yoW5JF43pF 45GFyUGF4rAr45Wr47KF98XFyrta1UC3W7G393XFy0vw4Sg3W7Xr17Jr4jyrWDu3Z3AFy7 trWqqrWjgFyUAw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxkF7I0E n4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I 0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17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ETxTS7MumSYwS2swrJV9/P+pNpmZ3vB3YAoSPW5PvjsHhuh3xSwIBCmrDDNvOZhkyuut9VDsYEF+RpOiKUpmGJyt6CQu7nOb2czyAiZ9lEQiTE0HpVVLstEZH7646DxFajODHmHtTZRn+LPZjb2TPb0MfS6sLdkRETwLqkdvuHDdD2381kXFkErV1MvYUIpdZs2pRz/As2b8LblHBL9KUdB1k3J+2fZwPipllyah9CibTIiACO9klUfXejLh9Wk8Dc8NPKFwadfdU2sj/oW62jvL2qu7Ud4IuafHjmP2R/2HSBwnV9U /Q6m/u/7 IeNCB71ItLvfl5j0DG0NTIGOdl2GMrwDD9WhLoy39vkqvUGSO1X0xiKpXZimkrn2S8MMtaRWap0T0mPTajJo0wj2hYBDynATrP+Zyxt06wiL1R2yN9j2FSNArN24kOm3xiMPPVyjMzDbzBwy2mFgqVHKa2/eq6r4tcQbQu7cOWcZOl486alCKnC1jL9sCRUJssCCmtzM3ibKYYe4= 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: List-Subscribe: List-Unsubscribe: From: Chen Ridong A memleak was found as bellow: unreferenced object 0xffff8881010d2a80 (size 32): comm "mkdir", pid 1559, jiffies 4294932666 hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @............... backtrace (crc 2e7ef6fa): [] __kmalloc_node_noprof+0x394/0x470 [] alloc_shrinker_info+0x7b/0x1a0 [] mem_cgroup_css_online+0x11a/0x3b0 [] online_css+0x29/0xa0 [] cgroup_apply_control_enable+0x20d/0x360 [] cgroup_mkdir+0x168/0x5f0 [] kernfs_iop_mkdir+0x5e/0x90 [] vfs_mkdir+0x144/0x220 [] do_mkdirat+0x87/0x130 [] __x64_sys_mkdir+0x49/0x70 [] do_syscall_64+0x68/0x140 [] entry_SYSCALL_64_after_hwframe+0x76/0x7e In the alloc_shrinker_info function, when shrinker_unit_alloc return err, the info won't be freed. Just fix it. Fixes: 307bececcd12 ("mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred}") Signed-off-by: Chen Ridong Acked-by: Qi Zheng Acked-by: Roman Gushchin Acked-by: Vlastimil Babka Acked-by: Kirill A. Shutemov Reviewed-by: Dave Chinner --- mm/shrinker.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index dc5d2a6fcfc4..4a93fd433689 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -76,19 +76,21 @@ void free_shrinker_info(struct mem_cgroup *memcg) int alloc_shrinker_info(struct mem_cgroup *memcg) { - struct shrinker_info *info; int nid, ret = 0; int array_size = 0; mutex_lock(&shrinker_mutex); array_size = shrinker_unit_size(shrinker_nr_max); for_each_node(nid) { - info = kvzalloc_node(sizeof(*info) + array_size, GFP_KERNEL, nid); + struct shrinker_info *info = kvzalloc_node(sizeof(*info) + array_size, + GFP_KERNEL, nid); if (!info) goto err; info->map_nr_max = shrinker_nr_max; - if (shrinker_unit_alloc(info, NULL, nid)) + if (shrinker_unit_alloc(info, NULL, nid)) { + kvfree(info); goto err; + } rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); } mutex_unlock(&shrinker_mutex);