From patchwork Thu Jul 13 14:14:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 119936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1864531vqm; Thu, 13 Jul 2023 07:29:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlFRv3VNvh4rWSfpI43+hRl5wGm5dwjr00S8zxbj0TWQ+N1KUoOQqcKyCUQznkxMNWMnwmyA X-Received: by 2002:a05:6a20:3d2a:b0:131:3598:f4e9 with SMTP id y42-20020a056a203d2a00b001313598f4e9mr1990241pzi.32.1689258592054; Thu, 13 Jul 2023 07:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689258592; cv=none; d=google.com; s=arc-20160816; b=hjgEPEOCyJ3b+Juj0r+RI5sCXL3K/+zZY8Pzxmfp9zSHfr+1DSU1GuJb0TBT/RaBix oMUVg4wVeIA1q96OznAejBa5qnJcHwdig6lFea5JBreO0vs70ZyCjt3ASe+GpXFnxygA +KXR/i75mPJgbIsAB1tFbzIRIjXsW3XA8LlWiyJnYq+TXbu1oIL4KHv8O7IU8YqqzcIL 7yJaakkPIZnuHNqZY/WpdziNJWbCANzrp4C33rd6mOyMPjuNoMF++4XzREd+w0fqmufg 9X67Ken4JYMg+VX2wkPCaPFAUgii8AxHyYJ6gwFLd0htnzdrtGwGRksL5sNiAnbf3WeL JXXg== 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 :message-id:date:subject:cc:to:from; bh=7n0NVJHB7Qp/tlqViU6BTAvSVM5wByNOkC/ZYunEHms=; fh=gI9FEBZwCPkanigZF8HYbw13aijx656e2P76SW8PY5Y=; b=evCHW1o3XtAMxc0GfbqU1amlBqc+yCO+XVFHqEKsvGg1BWZHEWjvWOo3Q9hLNjo/Pj k0zK6Eci2APPjFpDuPWA4j2MyALTiMQgh/o6ddGygzuP2Du61n62i/9s0U/RU5nBkUXr T8PuiUXBSRca5byjDWAjpWBTQ7K1nbbB0kMekvwvxBzefFQfRO2oTe5BS5a1iAjeYdvn 0kSWHLehAYBqpKjfNbpJt0G7Og6V5NCShigGd7VLAm1wSv8i16Wgp9ZMl7MyjbZ/DnJ2 Do1JFei8YjDxlti3u1raY4QVrmewE1n317IhSCU+eWhzK/TP2xbikj5zNXRBju9oanPy OkdA== 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 c13-20020a63ea0d000000b00553b9b1886bsi5249916pgi.621.2023.07.13.07.29.37; Thu, 13 Jul 2023 07:29:52 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234066AbjGMOPe (ORCPT + 99 others); Thu, 13 Jul 2023 10:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235205AbjGMOOy (ORCPT ); Thu, 13 Jul 2023 10:14:54 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CAFA30EC; Thu, 13 Jul 2023 07:14:41 -0700 (PDT) Received: from dggpeml500012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R1xR76DjmzVhlr; Thu, 13 Jul 2023 22:13:23 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 13 Jul 2023 22:14:38 +0800 From: Zheng Yejian To: , CC: , , Subject: [PATCH] traing: Fix memory leak of iter->temp when reading trace_pipe Date: Thu, 13 Jul 2023 22:14:35 +0800 Message-ID: <20230713141435.1133021-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500012.china.huawei.com (7.185.36.15) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771316017184757998 X-GMAIL-MSGID: 1771316017184757998 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 --- 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);