Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1864550ybl; Thu, 15 Aug 2019 02:32:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeVC4TKrevwkW4sz0TfFRqO4SjyniQscBZ5vr9VRiEvUvlrQBrdl9Ca9Ai554Lth0WZjQ4 X-Received: by 2002:a17:902:24b:: with SMTP id 69mr3364113plc.250.1565861548263; Thu, 15 Aug 2019 02:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565861548; cv=none; d=google.com; s=arc-20160816; b=EDQLYvh7tfKI0jhjPz98nWIFI7cI3gl8+0hw5gwSAVtPg0V0E9muJsGfS30CgDyMeG B7QSxyhyVNnq8FmCfyj7MUyIyx+1YIeIrHqc58DpNfmHUkmQzMaTrzkCesbo+tD3+sQ8 e1bP3yaue1gbQ6jnoSg8yrtZN3peAEpLY2jFY4qPvA4OYk433DA+0kzdmk+OSmpzTzG0 thPCeLDfvF/+VjIgGozp3UMlHy9zuJyBLi0guBxH4GaJLIxc+9GSCa/nW7/iXDu9Anln SHlYMe16lFT1hGlZ146U3XAyn8cF1BWd3sX55DPHRcKtA8L1UxzLpv9Hvg4G9kPUiS34 cVBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=qgQwcS9vqN6A1JMDyfTrlZSBFQeKPquDL/x8bhkf67s=; b=Z6UBiaXhrb3kPMWAIyidMaKAAop23dxNR1OoZelQylCzouydt3aR9jnKOY/rMbP4YC UG7CuTASBwup3ccRx6vLUrPTzJdVkYBTMMSW+QARUshsKTX4nFr+yYbGHwcPljI4uPFq GqYx6mMNPWbmyAggZD9v3g3X9YUApZ3+WFgAOyyEZTaTuQeKlRXyr0k2DDGmYiUCJu13 Jtt6AkFUrK66cF+xncY7Fvxsxit+ZLeY4QKG0+1X94wTnAFS+9NE7i23fDbbA/vW0ORp 6cEh147IetoRe6k6vBc1pM79ksbAaAO9s6JyL2chWn0jGQObLnl/Q+PS61zKky0r8YFA iFYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=DAp0EWbG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c18si628027pjo.105.2019.08.15.02.32.11; Thu, 15 Aug 2019 02:32:28 -0700 (PDT) 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=@zytor.com header.s=2019071901 header.b=DAp0EWbG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731081AbfHOJQw (ORCPT + 99 others); Thu, 15 Aug 2019 05:16:52 -0400 Received: from terminus.zytor.com ([198.137.202.136]:36681 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730389AbfHOJQw (ORCPT ); Thu, 15 Aug 2019 05:16:52 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x7F9GMYr2270342 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 15 Aug 2019 02:16:22 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x7F9GMYr2270342 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019071901; t=1565860583; bh=qgQwcS9vqN6A1JMDyfTrlZSBFQeKPquDL/x8bhkf67s=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=DAp0EWbGpB/Koi3PHlsDFJRtbPI22EluaRHClvqENR93qzBBldXchQi1tZWgtVvWT RmPSQTHju5eJ37s4FG5QGCDHUnOkkajq6miB9hnBxr7MWhTzWfVlN86WNZB8ZtNO5K JdOnmoORxGT7IoHVtJxpYQWv4oWVxHpTdakJ67xssoIQGTNFapbS/tRwPrNb6BEqkc hxo4vWG5z8Lc+US7m3X8hF/2MjhvSZjsKxG6gKWRQOfngVR7pWRUONPdPOipEk55HM yb7WlsiaERb5FagGvpCDJkiK9wakrZpTCeMTI7LSvNA9BOzzU/M78nwdGMeob+eniH Nqgzj5SojhROw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x7F9GLYb2270335; Thu, 15 Aug 2019 02:16:21 -0700 Date: Thu, 15 Aug 2019 02:16:21 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: linux-kernel@vger.kernel.org, acme@redhat.com, hpa@zytor.com, namhyung@kernel.org, mingo@kernel.org, jolsa@kernel.org, vincent.weaver@maine.edu, tglx@linutronix.de, peterz@infradead.org, alexander.shishkin@linux.intel.com Reply-To: namhyung@kernel.org, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, jolsa@kernel.org, vincent.weaver@maine.edu, peterz@infradead.org, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, acme@redhat.com In-Reply-To: <20190726211415.GE24867@kernel.org> References: <20190726211415.GE24867@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf session: Avoid infinite loop when seeing invalid header.size Git-Commit-ID: 57fc032ad643ffd018d66bd4c1bd3a91de4841e8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 57fc032ad643ffd018d66bd4c1bd3a91de4841e8 Gitweb: https://git.kernel.org/tip/57fc032ad643ffd018d66bd4c1bd3a91de4841e8 Author: Arnaldo Carvalho de Melo AuthorDate: Tue, 30 Jul 2019 10:58:41 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 12 Aug 2019 16:26:02 -0300 perf session: Avoid infinite loop when seeing invalid header.size Vince reported that when fuzzing the userland perf tool with a bogus perf.data file he got into a infinite loop in 'perf report'. Changing the return of fetch_mmaped_event() to ERR_PTR(-EINVAL) for that case gets us out of that infinite loop. Reported-by: Vince Weaver Tested-by: Vince Weaver Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lkml.kernel.org/r/20190726211415.GE24867@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/session.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 11e6093c941b..b9fe71d11bf6 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -1955,7 +1956,9 @@ fetch_mmaped_event(struct perf_session *session, /* We're not fetching the event so swap back again */ if (session->header.needs_swap) perf_event_header__bswap(&event->header); - return NULL; + pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx: fuzzed perf.data?\n", + __func__, head, event->header.size, mmap_size); + return ERR_PTR(-EINVAL); } return event; @@ -1973,6 +1976,9 @@ static int __perf_session__process_decomp_events(struct perf_session *session) while (decomp->head < decomp->size && !session_done()) { union perf_event *event = fetch_mmaped_event(session, decomp->head, decomp->size, decomp->data); + if (IS_ERR(event)) + return PTR_ERR(event); + if (!event) break; @@ -2072,6 +2078,9 @@ remap: more: event = fetch_mmaped_event(session, head, mmap_size, buf); + if (IS_ERR(event)) + return PTR_ERR(event); + if (!event) { if (mmaps[map_idx]) { munmap(mmaps[map_idx], mmap_size);