From patchwork Fri Jun 18 12:37:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Faiyaz Mohammed X-Patchwork-Id: 12331273 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,URIBL_BLOCKED, 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 92870C48BDF for ; Fri, 18 Jun 2021 12:38:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2373C613EC for ; Fri, 18 Jun 2021 12:38:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2373C613EC 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 702146B0070; Fri, 18 Jun 2021 08:38:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D9266B0071; Fri, 18 Jun 2021 08:38:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A1056B0072; Fri, 18 Jun 2021 08:38:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 26A426B0070 for ; Fri, 18 Jun 2021 08:38:23 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B4BEEC5B9 for ; Fri, 18 Jun 2021 12:38:22 +0000 (UTC) X-FDA: 78266797644.33.BF88A56 Received: from m43-7.mailgun.net (m43-7.mailgun.net [69.72.43.7]) by imf16.hostedemail.com (Postfix) with ESMTP id BC6B9801935E for ; Fri, 18 Jun 2021 12:38:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624019902; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=qiuLMl18HhFSYMKHcPeThGQ32zAb/F1gnFVEgwuX6pw=; b=hSsqLg+9nh6gzwpGPoldN+THuMpMWFzbnaZ9/Buc7dhYR9dkpegusf1IcVC0AXdakUpX4Rmt lM/FdB03f/K4r9ZADz4sdI5K53TEYgFwuOHrcg8gTaOb5uL1qg0dElEtAQ0Asz2fR/ETBPXX hS4HKqencvzrskYyyULCLcpAmso= X-Mailgun-Sending-Ip: 69.72.43.7 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-n07.prod.us-east-1.postgun.com with SMTP id 60cc93bbe27c0cc77f549c87 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 18 Jun 2021 12:38:19 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 86FB4C4360C; Fri, 18 Jun 2021 12:38:18 +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 6ACCCC433F1; Fri, 18 Jun 2021 12:38:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6ACCCC433F1 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 v1] mm: slub: fix the leak of alloc/free traces debugfs interface Date: Fri, 18 Jun 2021 18:07:55 +0530 Message-Id: <1624019875-611-1-git-send-email-faiyazm@codeaurora.org> X-Mailer: git-send-email 2.7.4 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=mg.codeaurora.org header.s=smtp header.b=hSsqLg+9; dmarc=none; spf=pass (imf16.hostedemail.com: domain of bounce@mg.codeaurora.org designates 69.72.43.7 as permitted sender) smtp.mailfrom=bounce@mg.codeaurora.org X-Stat-Signature: c1yqc9qi7bs4f9xxx6k4wpmzzzqimdpm X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BC6B9801935E X-HE-Tag: 1624019900-974787 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 [] invoke_syscall.constprop.0+0xdc/0x1d8 [] do_el0_svc+0xe4/0x298 [] el0_svc+0x20/0x30 [] el0t_64_sync_handler+0xb0/0xb8 [] el0t_64_sync+0x178/0x17c Fixes: 84a2bdb1b458fc968d6d9e07dab388dc679bd747 ("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 --- mm/slub.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fcb0c50..f006766 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5785,31 +5785,24 @@ 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; + v = ppos; if (*ppos < t->count) { - *ppos = ++*spos; - return spos; + ++*ppos; + return v; } - *ppos = ++*spos; + ++*ppos; 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 = {