Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13474533ybl; Sun, 29 Dec 2019 12:47:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyn+R8KdpdMYZdGBxmfWNCEFdRSwYD9wAooIiJHmiTmafrdX/NCAm0U+QgqROgc79lrCAbg X-Received: by 2002:a05:6830:109a:: with SMTP id y26mr66763469oto.227.1577652439721; Sun, 29 Dec 2019 12:47:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652439; cv=none; d=google.com; s=arc-20160816; b=ycwYKCeneuLL8WluRxs4wFdHBrVXKIK58eNXus2OPRVV+TjIFohsNWpL3G62SYHUf+ OFR8WR9OVdB2PON6GtLeiVP9powsofO7Divo/Cr8nk/TTbOp54dRN7dP0emo0ni7tYKc r7TXs62YGe0oC4GlmV9pIKx8OUZzIzZNCWAj7SkJyibgxFdQgC8u42cDMuvb6DtS0e3t DBZOnpFhPn4Uin833ImtlXrP6HTTpG7llOR0bZIgbv/CtHMxCNf71FGj0d0D8JoY98W8 OmhfiyIJ7Yb9PO+nfGRmWbUg+eWE9AkQWhzHe2ajHFu/Yon6DnZ8spgLuX6lKfeIwvdH YZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QHkNnSU2N1eZbiF8vcz5fgArtpRMxW7aG5SfoMummyo=; b=o+eeuKX1RngLZgF57WdHTOR1DsGXt5W9+M8BUXsrXWX6v50eLEqE75W8NkPvpSh3Ud 8ol/hZvx8XS9vgPDaUxZokAKMHOwCLdcJs1FihAcSdx6BL7yMg2Lq2xtZiiTr2zLDRWB aGLvOtPw4/Wrg/MfuT24jeHfo4FMeZM4Y5WuhZxxVWlWWMr5Ses8EvL2l16U+kJLzm16 uq/8QTFkW2Aug2fFjHo8JvAQ0GEQv0ZHcNQ5xe1fh4VQkTmugHuGunzxH6WFfAQq73cI cFwK7gUenCtKCyRyo+03xVz2OorMyXvPIYES+proc5IUFLUDJ9NOpsBJ4fqJwdIyu4D7 GyeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Vqvc/Bz6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z22si14322233otq.94.2019.12.29.12.47.08; Sun, 29 Dec 2019 12:47:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Vqvc/Bz6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732118AbfL2Rvg (ORCPT + 99 others); Sun, 29 Dec 2019 12:51:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:36904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731791AbfL2Rvb (ORCPT ); Sun, 29 Dec 2019 12:51:31 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A802A208C4; Sun, 29 Dec 2019 17:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641890; bh=LxcowDC/0csBoYn9Er4pH7ImDa7kP/A0hOSvLa8tDJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vqvc/Bz6t6donwK9mYvVu/snAbGM0n3K/s1QuyC4xaWXq6r+mM9jDFFOzbgsbl9RU mKDvbC52a6kpKIXqfRpBB89bZPmlTpg53La662fUGZr+6p441ClBEXuB+vZt4ud7U6 YtMqQjkZ94VAtrqgt+njGxMQlP0QTdxW2Y7eTDD4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Alexei Starovoitov , Andi Kleen , Daniel Borkmann , Jin Yao , John Garry , Kan Liang , Mark Rutland , Martin KaFai Lau , Namhyung Kim , Peter Zijlstra , Song Liu , Stephane Eranian , Yonghong Song , bpf@vger.kernel.org, clang-built-linux@googlegroups.com, netdev@vger.kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.4 254/434] perf tools: Splice events onto evlist even on error Date: Sun, 29 Dec 2019 18:25:07 +0100 Message-Id: <20191229172718.795111361@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Rogers [ Upstream commit 8e8714c3d157568b7a769917a5e05573bbaf5af0 ] If event parsing fails the event list is leaked, instead splice the list onto the out result and let the caller cleanup. An example input for parse_events found by libFuzzer that reproduces this memory leak is 'm{'. Signed-off-by: Ian Rogers Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Andi Kleen Cc: Daniel Borkmann Cc: Jin Yao Cc: John Garry Cc: Kan Liang Cc: Mark Rutland Cc: Martin KaFai Lau Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Cc: Yonghong Song Cc: bpf@vger.kernel.org Cc: clang-built-linux@googlegroups.com Cc: netdev@vger.kernel.org Link: http://lore.kernel.org/lkml/20191025180827.191916-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/parse-events.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b5e2adef49de..d5ea043d3fc4 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1927,15 +1927,20 @@ int parse_events(struct evlist *evlist, const char *str, ret = parse_events__scanner(str, &parse_state, PE_START_EVENTS); perf_pmu__parse_cleanup(); + + if (!ret && list_empty(&parse_state.list)) { + WARN_ONCE(true, "WARNING: event parser found nothing\n"); + return -1; + } + + /* + * Add list to the evlist even with errors to allow callers to clean up. + */ + perf_evlist__splice_list_tail(evlist, &parse_state.list); + if (!ret) { struct evsel *last; - if (list_empty(&parse_state.list)) { - WARN_ONCE(true, "WARNING: event parser found nothing\n"); - return -1; - } - - perf_evlist__splice_list_tail(evlist, &parse_state.list); evlist->nr_groups += parse_state.nr_groups; last = evlist__last(evlist); last->cmdline_group_boundary = true; -- 2.20.1