Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4177149rwi; Mon, 17 Oct 2022 02:35:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71emE5Ya4iP+7tZYvKREHUICudZ+jtzgFzKR7/wpvDhc6Jv40eVpDbpu1qdH0x3wXXh62L X-Received: by 2002:a17:903:2c2:b0:182:df88:e6d3 with SMTP id s2-20020a17090302c200b00182df88e6d3mr10986965plk.81.1665999359718; Mon, 17 Oct 2022 02:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999359; cv=none; d=google.com; s=arc-20160816; b=vEi0S0ytPNzEFbPP0Sbt7zegWtIMPviTL+pbA9tI4GRrcZokh4MhWNEkR5hsn47c7G TkS4ICwwv9pM+e2CGqNvQADuqWeiymlSmuJePagGJvppDxSFaMIlgJPLyKrCe8bVViqP tOsMhmzqFt7SLz7elnonTbOxFIhTOcurcu1kDSJyJtq4/AGkMz3SEoDwN1s3LSiKnZau FgB1TNgmlWf8RmIW7F9c9AjWbpzraQXzbMOSC1IpRjuCeo675bKd09SJIIUZ+Bf8xZD9 4c1OPbeARBdds1yRgq3Vcv3YNnhyV7uHfZcG6bePHQeMQVUYSRBgN8VtmCqXA+t3TE6F G/Ew== 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=xS9h+83SJakMuK5aeaj9DUw3UXXLiFxycEAA2IHmCxs=; b=VNHFI1lpqjg88OfYV0LDlJV4Ug+n5B3iO31qhZachaSuIUUtRCmVjUfq7TxfisS0lg MDcP9CEyG/fibO2GLnu5U+CT7DFsZKTfdQXr3RYCKZvM/D8fev/uNHTOK2I3ZYxpdqD/ MHnArivfc+I1ovyCImvTNlXfeeXWLnrR21TqdTbGQQywrQAjG66UuIJoRx2ZVuFObAZh Dg/z6ATfgvQgWhXqJnkj1loKzMWpUi0Ec3RvfgXDrAd6F/tzysnFKiYrvKI2CSgK5PMw WS2fz9SgI224wbzEOprlJLlRPwXmcnXiR7l1odtEiFnYlk+Dci4l7kOLw3t5KtrcpKGB TC8w== 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 u62-20020a638541000000b0044b64be8bb7si10447928pgd.678.2022.10.17.02.35.47; Mon, 17 Oct 2022 02:35:59 -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 S230317AbiJQJAs (ORCPT + 99 others); Mon, 17 Oct 2022 05:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbiJQJA0 (ORCPT ); Mon, 17 Oct 2022 05:00:26 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3205D1C429 for ; Mon, 17 Oct 2022 02:00:19 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MrW6c6SnXz1P7DS; Mon, 17 Oct 2022 16:55:36 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 17 Oct 2022 17:00:17 +0800 Received: from huawei.com (10.175.100.227) by kwepemm600008.china.huawei.com (7.193.23.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 17 Oct 2022 17:00:17 +0800 From: Shang XiaoJing To: , , CC: , Subject: [PATCH] tools lib traceevent: Fix double free in event_read_fields() Date: Mon, 17 Oct 2022 16:59:37 +0800 Message-ID: <20221017085937.8583-1-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600008.china.huawei.com (7.193.23.88) 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 +- 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 */ -- 2.17.1