Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3337461rwa; Tue, 23 Aug 2022 03:06:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NwT4nRsF+pBpeQAEcavYtgkd+Bv8xGJL8M1QiFqkvIDDSd33CPza2XDlCWVJjX7wyx1DA X-Received: by 2002:a17:907:6d8f:b0:73d:8416:908b with SMTP id sb15-20020a1709076d8f00b0073d8416908bmr5267695ejc.651.1661249219573; Tue, 23 Aug 2022 03:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661249219; cv=none; d=google.com; s=arc-20160816; b=Xhv7PTYroIUOx16/w0Fvtt8kRMg1KEKZEnq/dcDhUw0fKxZwAke3suHttF1qWikNQD s9hG8d8el8ba06caFZ6Zqa8t2JJDqLZ5zNYmbaqRQfyyBqqlZbE4E/iUFuC/oRUpP/Bh 1eRtI5jabcOwd9aLUi8Fv16gCEqz0rqo4m2mP99iLjJ7qqqOYoVkZd9eIYXTlc5BA00n V5+Rf8iZYOa7fSUnqscKa7DXNCrF7s4lK+ScfLf6QujDl+ZCag51L5CrqVZ/VUya/TQ0 jiWdDYMkOcJ8Rnx+1GhAjFyumJuwMzZCeEuOSe6aLDsBDkwJbQlGRHQ3v7C5xyUTzDQE zxkQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s50I/r4s5TjVy+0H4AgOKyif3L35cknTyzR5AaPZ6m8=; b=E3WyaBH+0uvueEaMXFAMnqa9vD2ZA/A7TKoRN4wjMOBw6eVbxckWmtfFwiGbpwy3uC mGHyym/uSeV49jY+mFOk8FRSHFxzdoWP5btOSGAD7Tvvp67gWdCseRm3KT5s+V4N7b3R ir9CaWym78FMgOdN/p5cXfxgJkpKB1s64Dzvts9+fZduRoCPYVie+9Xpt1u8Ac9cVt9w A2KAIZy9l8apT0y/Yui/e9bSi2DnExTRUqJiXnkWZAIG7uqSlVjGHc9Oxq0n1tE3ap1t jvqtxioJGeSfcnVoCny1SjBJV6LNhVL13u5rjjJgHGN6/EZyZmnf3ailqjvCo4qCTQhv Vn7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gQ+lIUdQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a50f686000000b00440e4be2c8bsi1644589edn.507.2022.08.23.03.06.34; Tue, 23 Aug 2022 03:06: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gQ+lIUdQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243860AbiHWKDv (ORCPT + 99 others); Tue, 23 Aug 2022 06:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345397AbiHWJ6V (ORCPT ); Tue, 23 Aug 2022 05:58:21 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD0E8A1D6D; Tue, 23 Aug 2022 01:48:04 -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 sin.source.kernel.org (Postfix) with ESMTPS id 8BABDCE1B53; Tue, 23 Aug 2022 08:48:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2E49C433D7; Tue, 23 Aug 2022 08:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244481; bh=nd5+KB9Lr171c9+sykLDGdxdvhZMEc6ArTh1VfBEg5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gQ+lIUdQyWqBqaVSRdiODBTW0I9K8KBPpIZ2dB0diJMcyybHiUjEElaDG3KzInE+v 2B6FrojRfOhkwIJVLkHXhW8fDgnzgso/8/hanQ+0LI00pH5k7yg3cyBQD1hmHegqpC MzXUfYIyS3bDXH1IuVRR8KSFXrJbSpcXB9fEmP4s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Ian Rogers , Jin Yao , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo Subject: [PATCH 5.15 100/244] perf parse-events: Fix segfault when event parser gets an error Date: Tue, 23 Aug 2022 10:24:19 +0200 Message-Id: <20220823080102.374205156@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Adrian Hunter commit 2e828582b81f5bc76a4fe8e7812df259ab208302 upstream. parse_events() is often called with parse_events_error set to NULL. Make parse_events_error__handle() not segfault in that case. A subsequent patch changes to avoid passing NULL in the first place. Fixes: 43eb05d066795bdf ("perf tests: Support 'Track with sched_switch' test for hybrid") Signed-off-by: Adrian Hunter Cc: Ian Rogers Cc: Jin Yao Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lore.kernel.org/r/20220809080702.6921-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/parse-events.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -196,9 +196,12 @@ static int tp_event_has_id(const char *d void parse_events__handle_error(struct parse_events_error *err, int idx, char *str, char *help) { - if (WARN(!str, "WARNING: failed to provide error string\n")) { - free(help); - return; + if (WARN(!str, "WARNING: failed to provide error string\n")) + goto out_free; + if (!err) { + /* Assume caller does not want message printed */ + pr_debug("event syntax error: %s\n", str); + goto out_free; } switch (err->num_errors) { case 0: @@ -224,6 +227,11 @@ void parse_events__handle_error(struct p break; } err->num_errors++; + return; + +out_free: + free(str); + free(help); } struct tracepoint_path *tracepoint_id_to_path(u64 config)