Message ID | 1667819090-4643-1-git-send-email-wangyufen@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1971536wru; Mon, 7 Nov 2022 02:46:56 -0800 (PST) X-Google-Smtp-Source: AMsMyM5MWjHgT1iJsiwFHOE6c0MXKXmhe5ar3nIdGOgdA0im5ODbCjuiTmnsch+y3p5hQXe1AEh9 X-Received: by 2002:a17:90a:9a8f:b0:212:ea8d:dc34 with SMTP id e15-20020a17090a9a8f00b00212ea8ddc34mr70371749pjp.30.1667818016585; Mon, 07 Nov 2022 02:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667818016; cv=none; d=google.com; s=arc-20160816; b=G16Vr6mIuFIk8t/WxhR8XQqYwuhOs3hYmXhwTodnRm2sGkSRARRq0m6kV2fbaqRVE9 f9UIk7JSC0gjcQYXNw+svqSMGWOc1DHvR+OonHL7s0siq+eDNjLGB7rB1KlWzNZRjZQq oChZcEsZHPa+rLghl3kO6fZAX/8UmN18ap5LS4VAgtFfStu3nK9qa4pck+6Qm1aFbGUG eqjUJduqB0XKTZueksFayg7/1ls5kTsIss5I38LZtyCWdYKwjnXXGAKLXIXEph7WsRmy JxHCzRpM41jbfurj12nusfnF3hd/wmA6B1+2DyM6arbPvOaZjdCv7eWdiwO09Q6r5FtN QFTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=h2vE3C4CTf35qe0HrtH9xxWQZYyUT2dKhlczrxYOEBA=; b=MLSDE8KOmxeBNAC73oyCOTn/Aph7u3tfCHgGznWXDbx+Lpzaw1FMufJbaGfyaiP2j5 JsfPxfpaGVSCEGH1q3aQJ2E0JYGJ3jqLc2isBz5v44cH+NvU0ckk5dXlmZFiDmnkoaDb FRXvhhuowtIvcfyaZOrqt/b4NPwc/3xgtQ02SyKO+mMuTXOGa1toJFbTpgD0htDVvViN KBzT2I3PntlImfQNtMpzcQrifRZ3it0HSDfCiix/4DhFnAhpcw4XJ3PLVtW3HMG+0K2s kjWL7PtPEroRWlaQU+0nH1PFzQzdD/5yVbQ5zo4AKL2A7P11fXkDovE6rE7hC6f6PCRT to2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a6558c7000000b0046feca13e25si10274315pgu.68.2022.11.07.02.46.42; Mon, 07 Nov 2022 02:46:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231440AbiKGKo1 (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 05:44:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231207AbiKGKoY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 05:44:24 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C7D321B0 for <linux-kernel@vger.kernel.org>; Mon, 7 Nov 2022 02:44:24 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N5SSD0mSRzpWGV; Mon, 7 Nov 2022 18:40:44 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 7 Nov 2022 18:44:22 +0800 From: Wang Yufen <wangyufen@huawei.com> To: <linux-kernel@vger.kernel.org> CC: <rostedt@goodmis.org>, <mhiramat@kernel.org>, Wang Yufen <wangyufen@huawei.com> Subject: [PATCH v2] tracing: fix memory leak in tracing_read_pipe Date: Mon, 7 Nov 2022 19:04:50 +0800 Message-ID: <1667819090-4643-1-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748832560081189148?= X-GMAIL-MSGID: =?utf-8?q?1748833944284693100?= |
Series |
[v2] tracing: fix memory leak in tracing_read_pipe
|
|
Commit Message
wangyufen
Nov. 7, 2022, 11:04 a.m. UTC
kmemleak reports this issue:
unreferenced object 0xffff888105a18900 (size 128):
comm "test_progs", pid 18933, jiffies 4336275356 (age 22801.766s)
hex dump (first 32 bytes):
25 73 00 90 81 88 ff ff 26 05 00 00 42 01 58 04 %s......&...B.X.
03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<00000000560143a1>] __kmalloc_node_track_caller+0x4a/0x140
[<000000006af00822>] krealloc+0x8d/0xf0
[<00000000c309be6a>] trace_iter_expand_format+0x99/0x150
[<000000005a53bdb6>] trace_check_vprintf+0x1e0/0x11d0
[<0000000065629d9d>] trace_event_printf+0xb6/0xf0
[<000000009a690dc7>] trace_raw_output_bpf_trace_printk+0x89/0xc0
[<00000000d22db172>] print_trace_line+0x73c/0x1480
[<00000000cdba76ba>] tracing_read_pipe+0x45c/0x9f0
[<0000000015b58459>] vfs_read+0x17b/0x7c0
[<000000004aeee8ed>] ksys_read+0xed/0x1c0
[<0000000063d3d898>] do_syscall_64+0x3b/0x90
[<00000000a06dda7f>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
iter->fmt alloced in
tracing_read_pipe() -> .. ->trace_iter_expand_format(), but not
freed, to fix, add free in tracing_release_pipe()
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
v1 -> v2: del if (iter->fmt), free iter->fmt directly
kernel/trace/trace.c | 1 +
1 file changed, 1 insertion(+)
Comments
在 2022/11/7 19:04, Wang Yufen 写道: > kmemleak reports this issue: > > unreferenced object 0xffff888105a18900 (size 128): > comm "test_progs", pid 18933, jiffies 4336275356 (age 22801.766s) > hex dump (first 32 bytes): > 25 73 00 90 81 88 ff ff 26 05 00 00 42 01 58 04 %s......&...B.X. > 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [<00000000560143a1>] __kmalloc_node_track_caller+0x4a/0x140 > [<000000006af00822>] krealloc+0x8d/0xf0 > [<00000000c309be6a>] trace_iter_expand_format+0x99/0x150 > [<000000005a53bdb6>] trace_check_vprintf+0x1e0/0x11d0 > [<0000000065629d9d>] trace_event_printf+0xb6/0xf0 > [<000000009a690dc7>] trace_raw_output_bpf_trace_printk+0x89/0xc0 > [<00000000d22db172>] print_trace_line+0x73c/0x1480 > [<00000000cdba76ba>] tracing_read_pipe+0x45c/0x9f0 > [<0000000015b58459>] vfs_read+0x17b/0x7c0 > [<000000004aeee8ed>] ksys_read+0xed/0x1c0 > [<0000000063d3d898>] do_syscall_64+0x3b/0x90 > [<00000000a06dda7f>] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > iter->fmt alloced in > tracing_read_pipe() -> .. ->trace_iter_expand_format(), but not > freed, to fix, add free in tracing_release_pipe() Fixes: efbbdaa22bb7 ("tracing: Show real address for trace event arguments") > Signed-off-by: Wang Yufen <wangyufen@huawei.com> > --- > v1 -> v2: del if (iter->fmt), free iter->fmt directly > kernel/trace/trace.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 47a44b0..f9d98e7 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -6657,6 +6657,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file) > mutex_unlock(&trace_types_lock); > > free_cpumask_var(iter->started); > + kfree(iter->fmt); > mutex_destroy(&iter->mutex); > kfree(iter); >
On Mon, 7 Nov 2022 19:45:04 +0800 wangyufen <wangyufen@huawei.com> wrote: > > 在 2022/11/7 19:04, Wang Yufen 写道: > > kmemleak reports this issue: > > > > unreferenced object 0xffff888105a18900 (size 128): > > comm "test_progs", pid 18933, jiffies 4336275356 (age 22801.766s) > > hex dump (first 32 bytes): > > 25 73 00 90 81 88 ff ff 26 05 00 00 42 01 58 04 %s......&...B.X. > > 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [<00000000560143a1>] __kmalloc_node_track_caller+0x4a/0x140 > > [<000000006af00822>] krealloc+0x8d/0xf0 > > [<00000000c309be6a>] trace_iter_expand_format+0x99/0x150 > > [<000000005a53bdb6>] trace_check_vprintf+0x1e0/0x11d0 > > [<0000000065629d9d>] trace_event_printf+0xb6/0xf0 > > [<000000009a690dc7>] trace_raw_output_bpf_trace_printk+0x89/0xc0 > > [<00000000d22db172>] print_trace_line+0x73c/0x1480 > > [<00000000cdba76ba>] tracing_read_pipe+0x45c/0x9f0 > > [<0000000015b58459>] vfs_read+0x17b/0x7c0 > > [<000000004aeee8ed>] ksys_read+0xed/0x1c0 > > [<0000000063d3d898>] do_syscall_64+0x3b/0x90 > > [<00000000a06dda7f>] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > iter->fmt alloced in > > tracing_read_pipe() -> .. ->trace_iter_expand_format(), but not > > freed, to fix, add free in tracing_release_pipe() > Fixes: efbbdaa22bb7 ("tracing: Show real address for trace event arguments") Oops, good catch! Cc: stable@vger.kernel.org Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thank you, > > Signed-off-by: Wang Yufen <wangyufen@huawei.com> > > --- > > v1 -> v2: del if (iter->fmt), free iter->fmt directly > > kernel/trace/trace.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > index 47a44b0..f9d98e7 100644 > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -6657,6 +6657,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file) > > mutex_unlock(&trace_types_lock); > > > > free_cpumask_var(iter->started); > > + kfree(iter->fmt); > > mutex_destroy(&iter->mutex); > > kfree(iter); > >
On Mon, 7 Nov 2022 22:17:10 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > Oops, good catch! > > Cc: stable@vger.kernel.org > > Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Queued, thanks Wang and Masami! -- Steve
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 47a44b0..f9d98e7 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6657,6 +6657,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file) mutex_unlock(&trace_types_lock); free_cpumask_var(iter->started); + kfree(iter->fmt); mutex_destroy(&iter->mutex); kfree(iter);