From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F17C4332F for ; Thu, 20 Oct 2022 21:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbiJTVXY (ORCPT ); Thu, 20 Oct 2022 17:23:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbiJTVXW (ORCPT ); Thu, 20 Oct 2022 17:23:22 -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 2B9EB198986 for ; Thu, 20 Oct 2022 14:23:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BD77361CD3 for ; Thu, 20 Oct 2022 21:23:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1B61C433D6; Thu, 20 Oct 2022 21:23:19 +0000 (UTC) Date: Thu, 20 Oct 2022 17:23:24 -0400 From: Steven Rostedt To: Shang XiaoJing Cc: , , Subject: Re: [PATCH] tools lib traceevent: Fix double free in event_read_fields() Message-ID: <20221020172324.66c6927f@gandalf.local.home> In-Reply-To: <20221017085937.8583-1-shangxiaojing@huawei.com> References: <20221017085937.8583-1-shangxiaojing@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Oct 2022 16:59:37 +0800 Shang XiaoJing wrote: > There is a double free in event_read_fields(). After calling free_token() > to free the token, if append() failed, then goto fail, which will call > free_token() again. Triggered by compiling with perf and run "perf sched > record". Fix the double free by goto fail_expect instead of fail while > append() failed, which won't call redundant free_token(). > > BUG: double free > free(): double free detected in tcache 2 > Aborted > > Fixes: d286447f23cd ("tools lib traceevent: Handle realloc() failure path") > Signed-off-by: Shang XiaoJing > --- > tools/lib/traceevent/event-parse.c | 2 +- tool/lib/traceevent is deprecated. Can you send this patch to linux-trace-devel@vger.kernel.org against https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ Thanks! -- Steve > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c > index 8e24c4c78c7f..e0a5a22fe702 100644 > --- a/tools/lib/traceevent/event-parse.c > +++ b/tools/lib/traceevent/event-parse.c > @@ -1594,7 +1594,7 @@ static int event_read_fields(struct tep_event *event, struct tep_format_field ** > ret = append(&brackets, "", "]"); > if (ret < 0) { > free(brackets); > - goto fail; > + goto fail_expect; > } > > /* add brackets to type */