Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1207757rwp; Thu, 13 Jul 2023 07:40:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUlMLTiANzKymkfstTtGMsYTJJqWuMdsqFpduIXPYUDeLybCjy9x1mrflrzVfpHOOQGo7L X-Received: by 2002:a05:6358:6f0c:b0:134:ec7e:90f1 with SMTP id r12-20020a0563586f0c00b00134ec7e90f1mr2109108rwn.10.1689259230213; Thu, 13 Jul 2023 07:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689259230; cv=none; d=google.com; s=arc-20160816; b=BxquJpVxHxAv2VY5WLl5g+79JTAzjvhpxodRDvasu2LhonZmgDi3qI8RFJUMPPYEfa cRlLR1r63W0krlmK7zoIMeRakSfvKHjJEjf5pDUo2NzCWaK6Hv9XfuTM/thEnuYkGL9L OyF86hka2ms1bt7NaSU5C+HGEkwSxuIi+5i04aNTexPMf5AicVr82C8EMu0xibAfjUC1 p32Ak/8r2eB9Mss3u9S66o+Hr1EvOz9IHHDOqVutJ5w4wDHbiX4v9Xb4wRxqC3kgJ8X0 5YD0DGOl6++1BUOFONLVL0JMPh+gUVeEfzg2sFAZWQr8ZZ9e0S/JY1EhK51wwo6ZrbA5 SN8g== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a63e314000000b00543a6cc74bfsi5116832pgh.634.2023.07.13.07.40.17; Thu, 13 Jul 2023 07:40:30 -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 S235272AbjGMOPe (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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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); -- 2.25.1