From patchwork Mon Jun 21 04:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Faiyaz Mohammed X-Patchwork-Id: 12333777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 571DDC48BE5 for ; Mon, 21 Jun 2021 04:01:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C83CA61009 for ; Mon, 21 Jun 2021 04:01:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C83CA61009 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 47B7B6B0073; Mon, 21 Jun 2021 00:01:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 452EC6B0074; Mon, 21 Jun 2021 00:01:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F3D96B0075; Mon, 21 Jun 2021 00:01:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id F3A9F6B0073 for ; Mon, 21 Jun 2021 00:01:19 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8FC738249980 for ; Mon, 21 Jun 2021 04:01:19 +0000 (UTC) X-FDA: 78276381078.33.1253500 Received: from so254-9.mailgun.net (so254-9.mailgun.net [198.61.254.9]) by imf03.hostedemail.com (Postfix) with ESMTP id 432DBC0237D3 for ; Mon, 21 Jun 2021 04:01:19 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624248079; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=gkrITEleuMWfHYFVxXi8Ks0XBVcCGvg8UG3qlvDGPi8=; b=lDl+WVSBnJCO7U9zivqvCKb5Ec4M6Jpvmel9mJxNRM1cZPYZvnjNbnHCh+9lLy3JoaCW6jwN F6E3rtnkWSEU2caDLj+YXpJvd87zRTIqUsyTp9fqmTdgOqmP5gx+OVEZ91Sr8vrTNTKarjq6 wGyi4ifJcYSG8YuW40I9il83rVw= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyIwY2Q3OCIsICJsaW51eC1tbUBrdmFjay5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 60d00f0e2eaeb98b5e5756f7 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 21 Jun 2021 04:01:18 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id F09E0C43460; Mon, 21 Jun 2021 04:01:17 +0000 (UTC) Received: from faiyazm-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: faiyazm) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5A66EC433F1; Mon, 21 Jun 2021 04:01:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5A66EC433F1 From: Faiyaz Mohammed To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, greg@kroah.com, glittao@gmail.com, andy.shevchenko@gmail.com Cc: vinmenon@codeaurora.org, catalin.marinas@arm.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Faiyaz Mohammed Subject: [PATCH v2] mm: slub: fix the leak of alloc/free traces debugfs interface Date: Mon, 21 Jun 2021 09:31:00 +0530 Message-Id: <1624248060-30286-1-git-send-email-faiyazm@codeaurora.org> X-Mailer: git-send-email 2.7.4 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=mg.codeaurora.org header.s=smtp header.b=lDl+WVSB; dmarc=none; spf=pass (imf03.hostedemail.com: domain of bounce@mg.codeaurora.org designates 198.61.254.9 as permitted sender) smtp.mailfrom=bounce@mg.codeaurora.org X-Stat-Signature: zhm4yuoofznb1o6tgtq1sptoz3ejx1t3 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 432DBC0237D3 X-HE-Tag: 1624248079-223113 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: Fix the leak of alloc/free traces debugfs interface, reported by kmemleak like below, unreferenced object 0xffff00091ae1b540 (size 64): comm "lsbug", pid 1607, jiffies 4294958291 (age 1476.340s) hex dump (first 32 bytes): 02 00 00 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b ........kkkkkkkk 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk backtrace: [] slab_post_alloc_hook+0xa0/0x418 [] kmem_cache_alloc_trace+0x1e4/0x378 [] slab_debugfs_start+0x30/0x50 slab_debugfs_start at mm/slub.c:5831 [] seq_read_iter+0x214/0xd50 [] seq_read+0x28c/0x418 [] full_proxy_read+0xdc/0x148 [] vfs_read+0x104/0x340 [] ksys_read+0xf8/0x1e0 [] __arm64_sys_read+0x74/0xa8 Fixes: 3589836402ca ("mm: slub: move sysfs slab alloc/free interfaces to debugfs") Link: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/mm/slub.c?h=next-20210617&id=84a2bdb1b458fc968d6d9e07dab388dc679bd747 Signed-off-by: Faiyaz Mohammed --- v2 changes: - Updated the comparison in slab_debugfs_next(). v1 changes: - https://lore.kernel.org/linux-mm/1624019875-611-1-git-send-email-faiyazm@codeaurora.org/ mm/slub.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fcb0c50..971d61d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5785,31 +5785,23 @@ static int slab_debugfs_show(struct seq_file *seq, void *v) static void slab_debugfs_stop(struct seq_file *seq, void *v) { - kfree(v); } static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos) { - loff_t *spos = v; struct loc_track *t = seq->private; - if (*ppos < t->count) { - *ppos = ++*spos; - return spos; - } - *ppos = ++*spos; + v = ppos; + ++*ppos; + if (*ppos <= t->count) + return v; + return NULL; } static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) { - loff_t *spos = kmalloc(sizeof(loff_t), GFP_KERNEL); - - if (!spos) - return NULL; - - *spos = *ppos; - return spos; + return ppos; } static const struct seq_operations slab_debugfs_sops = {