From patchwork Mon Oct 14 03:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13834129 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 87483CF259D for ; Mon, 14 Oct 2024 03:32:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA69D6B0088; Sun, 13 Oct 2024 23:32:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D56866B0089; Sun, 13 Oct 2024 23:32:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1D7F6B008A; Sun, 13 Oct 2024 23:32:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A28E86B0088 for ; Sun, 13 Oct 2024 23:32:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 350F1C0ADE for ; Mon, 14 Oct 2024 03:32:04 +0000 (UTC) X-FDA: 82670784336.23.B92E52A Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 4D1E8C0002 for ; Mon, 14 Oct 2024 03:32:01 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1728876589; 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=o9cZtyZDE6sVsS8jykojxPmKWgRcJ6XCNWfmFetBUv4=; b=CdKzIKtJxbya4x9yx4gzQaIjg9x5OcYBcuJwIce0NN6v0eA6hTXlbFdv4TWHtR323rGMX9 6hUR65uUdJyN/bNysEKapyiV9T1K0FgpC/IRUggFRUvwth/4QWq0mCCCSH1ALj4dpnZCcr aC8wCQyusm4sfpbUiL2Q6KrusxiAFYg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728876589; a=rsa-sha256; cv=none; b=FPKFYVWlHMokC3a1Myqf7kGcbCmvqBxsVfgaOOlgDioA0xJ46PCQf+w7ThKpId3COIJE4v F0tkJWw7Mmcm048Y40T8Bp3VeVK4pZyS6JtNSiicVUI8DUB5iN0cRcM2zTU8JPESW2c9S1 rjvu4PB2/5NnbTci64Oh0O3nqFP/Rx8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4XRjSz118Qz4f3jkL for ; Mon, 14 Oct 2024 11:31:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 196C41A0568 for ; Mon, 14 Oct 2024 11:31:59 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgBnm8emkAxnh_smEA--.18252S2; Mon, 14 Oct 2024 11:31:58 +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 v2] mm: shrinker: avoid memleak in alloc_shrinker_info Date: Mon, 14 Oct 2024 03:23:36 +0000 Message-Id: <20241014032336.482088-1-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnm8emkAxnh_smEA--.18252S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uF13Cr4rur4Dtr4UGr17Wrg_yoW8Ar13pF 43GryUGF4rCr15Gr47ta45Xry0qa12ka4xJ393Xry8tw4fW3W5Wr17Ar4UKrWDW3WkAFW7 tF4DtrWj9345J3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyEb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI 7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6x AIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY 1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU17KsUUUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspamd-Queue-Id: 4D1E8C0002 X-Stat-Signature: hyoo53tsyn9hzqzakjprqz5ed9wkwbkg X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1728876721-171940 X-HE-Meta: U2FsdGVkX1+LMX1JinsL6ugh/1/FoF21gcY5A0zynABgDUjs07rDwIFhOfhvc3mf6IsqoPg+9hewpg6Kmdd7U1Va6FPmJtbHnNAAOqLCzSFsBQ4i6erZ8j6Ms6ZBfRwnX3PMVKuYHliHizNH3fYjKfyDY8l136nOtiXsXcBf0bi1ql3Uy6Ua1O5px0qyqdftPb4vY/f1+6i59dfzgRTkViZt4FOnneIR66WrRToqqvqX55ucO4O1CcIwkfW3UpMf4u1x24WEFKUzMyCC7VGYc4cmzzLp9qcT6CDqYgpiW7fveDUXQvRdcwR4Q0G/kQoTgNNPHESpL3IUhRuePM07Th+OYvKAEjjjJerWNn74GH1K4Cdseb1CZ6zAejVEKntqE5YFJHAwINTuqZ1gi8U9q13Qis10O5QJArg731zSTD/VvOl9aIJC5t8Ow5xiGF9YjnaUtiUhF/SCDb20LKgGthtfYvmiGMlWT89ojcoJgg5b4I1+wYPvOE52KyxLZ+i7jk5P89YrrWj2nETAMUMpztLxNiPrpwEq8b7WddvuRAgNvW/3Aj677jX7/sNgvnL0l9A9oFDlrL4syA6446YQmlVHDtvfAzBiCuThpaQmv6lyzJn86Is6schstAwjg1ak4yh7TQtRMrztwV88XD3z7n/HVlQHo9V9xLxTyJlyZh/LbFx+GTRRDqnhKprUMD4qP4JpzF16lZmuJUIp4rv1l6KlqcNnJJwPD26vH8pPm9iUFdbruGwBh3Yxio9YIIeYShTI+QH2jqMXRcoUKoUnuK3mJN8mRxug5Q2/UyfJdsJ/fEjx9dWvdLqX1oNX0vSpOaLJdOAGMJnsj13UNoSNTtEl0FQNdfINE9OARBSNRmr3229DI4Jhiiwi3udpRbvWfT08X6HCw3qtlqVQcLoQ8FszigB9pCs/MLloegH/P9W3jDtQm/MN1Ewrw50LAyhFtKYBbcXJy5qgxuTS5pA k8qmdE1E uinoqlKE5f3OPhgAjZvWDCGU0lLQrMXciKXC8m5HBHZDwcFcd1Ar9PobzF04HK1oBKeq/PJa/BgDte3jrDlfTGaLkAg71dxcDMR4oLACO2uTjIvqbuBXCs41STIx7Ry6BK6mS3tdPFhqf9bBlXCyxpk/xWFhdSr/o6uYKDQTKJRJClRs= 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: Roman Gushchin Acked-by: Vlastimil Babka --- mm/shrinker.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/shrinker.c b/mm/shrinker.c index dc5d2a6fcfc4..92270413190d 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -97,6 +97,7 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) err: mutex_unlock(&shrinker_mutex); + kvfree(info); free_shrinker_info(memcg); return -ENOMEM; }