From patchwork Fri Oct 11 14:21:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13832609 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 DA7AAD0D795 for ; Fri, 11 Oct 2024 14:29:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 622F96B0082; Fri, 11 Oct 2024 10:29:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D1D56B00A7; Fri, 11 Oct 2024 10:29:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4730F6B00A9; Fri, 11 Oct 2024 10:29:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1D41D6B0082 for ; Fri, 11 Oct 2024 10:29:35 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B943CABC4E for ; Fri, 11 Oct 2024 14:29:25 +0000 (UTC) X-FDA: 82661554626.08.DBB3D7E Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 63984140008 for ; Fri, 11 Oct 2024 14:29:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.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=1728656928; a=rsa-sha256; cv=none; b=tTmeKuql5vsIv8VqiUWo5OR5w/uedWVyOwYz8R4DdYfhx//heflNOiBefR3HDI8JgppKBQ yQVmA+Wi773zXmxuUSdD3jGiJYldRYlGS8D2iH9N5qGWmOx9DHlVVCbX/vthwzhjK5KLBv zK7XTXKzqxCU/VU7hB22DqYtAqaF4HQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.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=1728656928; 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=YGeTSNEcsBAPVLf7TnO0gW9qtbtjhxo2GZH7GqyeWcA=; b=HlvthcD8Qcj9osJj1Xam4g+bzE3mJWIqmZTexdF1TXbaHrZEf6v/B1Gtcq4hxGLOYGSM8V VgH+w8HyAE7YhzqXwdODS358hOhuKG9mlptLm8XLfujIMRbvDWx7hHcnRGX0Uk/9xeNJAx ldXbLDAmwVpfhfMufNcJqjTsM+pjIvg= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4XQ8Bn6dHBz4f3nTw for ; Fri, 11 Oct 2024 22:29:05 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 9C8F71A092F for ; Fri, 11 Oct 2024 22:29:23 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgC36sY6NglncsU4Dw--.40967S2; Fri, 11 Oct 2024 22:29:23 +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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, chenridong@huawei.com, wangweiyang2@huawei.com Subject: [PATCH] mm: shrinker: avoid memleak in alloc_shrinker_info Date: Fri, 11 Oct 2024 14:21:05 +0000 Message-Id: <20241011142105.391157-1-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: gCh0CgC36sY6NglncsU4Dw--.40967S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uF13Cr4rur4Dtr4UGr17Wrg_yoW8Cw1UpF 43WFyUGF4rCr45Gr47ta45Xry0qa1xCa47Gws3Xry0yw4fW3W3Wr17Ar4UtrWDW3WkAFy7 tF4qqrWj934UCw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyCb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2 j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7x kEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY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vF1KLUSgegmw27hkHofDPX+sUIwE2QJxuwnzk33Vf+FQ4bK2Ee9gvxjEMCbKisH5/XXiCE4zm8qc8kKAyTMM7//PTc0nYHLRXiJpSB99jDJcbxeKsn7uXcURthvk03NpU8MOeuJpWkPEiQCwR4kjX8yxkrDczLjZk0OUc3j1jvZIMGkSdaZeblFseVgJqYhwovS5JpLXeq6pgQBFrzNrB9Iq5D4hv77TemE4pFLDx kHy4Cx6K whxB+CB0I1mMFd/PLfTYMwXyLst/XB32R+5YyIjZ55nWjpQaq93tdvBHu57Jic7vEUHE5zf1nfwByCSv/IrMYSZwmmcbEglIYGu6o/wpOC8SHaAGTXhMXnsF6/QxGL/QiUH9Ez+vqpIhTFFbsn47CLhG9aUpizca6fXB4T8CVuXIaLKsGXcSeS5u96w== 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 --- mm/shrinker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index dc5d2a6fcfc4..e4b795ee6d2e 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -87,8 +87,10 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) 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);