Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1221309rwp; Thu, 13 Jul 2023 07:52:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlE5ZBUqB+lO797cyH/lJFDr0EoajW8v2cXutG1chClUi5VZ1dgDW9ObRYDBeBgHYRt01wkL X-Received: by 2002:a17:906:7496:b0:993:d617:bdc8 with SMTP id e22-20020a170906749600b00993d617bdc8mr1784156ejl.7.1689259973443; Thu, 13 Jul 2023 07:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689259973; cv=none; d=google.com; s=arc-20160816; b=zQHOffxl8WdZNGKAxWh3v/lks8ybmliQK6aBQcbcUkN0ugJ4mTXqs4jEkT8pBYQDbR 8r27+CMXytY+yMMcdfvnlczH6YYks3CFFE6NCE5HXmHlmhCrK2o9sjadiaLgAcR/1YZp 23c/L9Z40SLmHShYo6d17jxal87Yg2Qx9paekV6wS+2L/mj2XsqAh36qT6vpXyZfCJBR vvtz5pgtga8z4eA10udAbg3rQPAnOXzi5o2fPgksJz6ZQgjEKkekJYprGRSzqerYYALw jE+M8YBswEEQg2AkzItahrNELzzgKzxOSqg035Ey5ymTvRUBzXWYtpM/6yEHdLLB7av7 tjTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=2l+f4nR266ptsITcZ4d0p/ujeuQ39FVOoiayv/jxvGc=; fh=zv7czJ9RKlBAqC7Fh/dPyQDhgz54x8oQKyWX9NfKcvU=; b=PTm+2M9TNGEdOXXUszopi536dtLQFMGOvnosI4wcGWlFiONHSdOFpcvNpW4+tUynMP Rv4LwtXfoFTQ1X1idztjK08LfrtP5BP1ZoF1CbJP6FRYjqX+dsJl7lwuVHilqrQFuIu7 0dSDywUSIVDEynnyyRu+TxmQtA88hjU8nj2WDKwTHjh/eVzi1xIYVIfpNj5wBUVdqT4Y v2o+ViITJVONdpqHNE47fZ+sd/JlkRvYEag0U5mbo2L95DV9RmMH0g/q1c50dntDGmSB eC5Xfv/lDnWJ296HbAAzv92jKikyd/ao00MiOFFSlvp3DMW2SYPq+1/PXD+00Dre9xz0 56dQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a17090695d100b0099364d9f0e3si395215ejy.562.2023.07.13.07.52.28; Thu, 13 Jul 2023 07:52:53 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230509AbjGMOeD (ORCPT + 99 others); Thu, 13 Jul 2023 10:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjGMOeA (ORCPT ); Thu, 13 Jul 2023 10:34:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 382E02702; Thu, 13 Jul 2023 07:33:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 84081612FB; Thu, 13 Jul 2023 14:33:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56B13C433C7; Thu, 13 Jul 2023 14:33:55 +0000 (UTC) Date: Thu, 13 Jul 2023 10:33:53 -0400 From: Steven Rostedt To: Zheng Yejian Cc: , , , Linus Torvalds Subject: Re: [PATCH] traing: Fix memory leak of iter->temp when reading trace_pipe Message-ID: <20230713103353.29cae218@gandalf.local.home> In-Reply-To: <20230713141435.1133021-1-zhengyejian1@huawei.com> References: <20230713141435.1133021-1-zhengyejian1@huawei.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Jul 2023 22:14:35 +0800 Zheng Yejian wrote: > kmemleak reports: > unreferenced object 0xffff88814d14e200 (size 256): > comm "cat", pid 336, jiffies 4294871818 (age 779.490s) > hex dump (first 32 bytes): > 04 00 01 03 00 00 00 00 08 00 00 00 00 00 00 00 ................ > 0c d8 c8 9b ff ff ff ff 04 5a ca 9b ff ff ff ff .........Z...... > backtrace: > [] __kmalloc+0x4f/0x140 > [] trace_find_next_entry+0xbb/0x1d0 > [] trace_print_lat_context+0xaf/0x4e0 > [] print_trace_line+0x3e0/0x950 > [] tracing_read_pipe+0x2d9/0x5a0 > [] vfs_read+0x143/0x520 > [] ksys_read+0xbd/0x160 > [] do_syscall_64+0x3f/0x90 > [] entry_SYSCALL_64_after_hwframe+0x6e/0xd8 > > when reading file 'trace_pipe', 'iter->temp' is allocated or relocated > in trace_find_next_entry() but not freed before 'trace_pipe' is closed. > > To fix it, free 'iter->temp' in tracing_release_pipe(). > > Signed-off-by: Zheng Yejian Why is it that every time I send a pull request to Linus, I get another fix??? Anyway, Linus, hold off. I'll send a v3 with this included as well. -- Steve > --- > kernel/trace/trace.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 4529e264cb86..94cfaa884578 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -6764,6 +6764,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file) > > free_cpumask_var(iter->started); > kfree(iter->fmt); > + kfree(iter->temp); > mutex_destroy(&iter->mutex); > kfree(iter); >