Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3885168ybi; Mon, 29 Jul 2019 14:37:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcMviTTy0Hkjj9nX1btDAPnBPeAQFXGDvTVCKqXXpY5lLkhK2IrLxnLB66jJ6F6/TWTKJF X-Received: by 2002:a63:1749:: with SMTP id 9mr17010804pgx.0.1564436241291; Mon, 29 Jul 2019 14:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564436241; cv=none; d=google.com; s=arc-20160816; b=WAsLfFgU+ji1/tbh6P1CTSOZYRpgvICgWQe4Yv4tsXLzy+TkjcvJbV25JlkHQTlYTW +f3dNrsfPE5vAbAvEKVbe9Lp6RTFH7CLCsjL1sKDSe6Ezd1miPPf4zysGHmzl/Kk65sX n9v4imFyPgUOCCfhsgx71gg+hbimaKdxwGi58m3/cdoDMeNh/Vd7JtV3uPLDV00dKVYO 1K4kWe6v5mqfTBkFychMeBgFC84WMD80Nj2MTeWsRKYEZ/JVajhhYhcVQtDwYSY+N2/E yFlEEVjHjA7Q548N4zqF8UQ8DO7LqW4ytQShfmDsiptzHDyt/L0PQA3AQmQY6Vw3AUE1 XghQ== 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=2Q+gAWKnOwqPd2IiB5D58yU98y/gLGjiukjiCr8EDFs=; b=mvj8svrzsgHl7hfCavx9y/eucaVq+z5FmsDHEyooA5809c3XbtGY3qqUkVahnbIPNn 9QOwdbydnBZnsjHO750TnzfT780T0gaxh3EIXRlkloz2lnrj0ADM2rS4Davu6qTkDoyV 0Fb4NnDbiqK70dKpS3GssiErIhGIpcLddDIq9j6VlI0uMZ+oGzlLZxv02Cjdr2rkGJkI hqfs1q0ccDFysC5d9PKPlC4IXVD0nTC2MnnBGwnD7sksAuNwJurMe9RFg9NF2pE+QL9w sCz5pSDtYN/mRwzASxhk/gnFkemIGTY4uHmS/eyNafDSb1xubCnwumdUnWJSylNVC3D1 9KFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=Nvj7mcvG; 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 i198si27328348pfe.228.2019.07.29.14.37.06; Mon, 29 Jul 2019 14:37:21 -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=Nvj7mcvG; 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 S2388679AbfG2Ves (ORCPT + 99 others); Mon, 29 Jul 2019 17:34:48 -0400 Received: from terminus.zytor.com ([198.137.202.136]:60063 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388600AbfG2Ves (ORCPT ); Mon, 29 Jul 2019 17:34:48 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x6TLYVLH2941388 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 29 Jul 2019 14:34:31 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x6TLYVLH2941388 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019071901; t=1564436072; bh=2Q+gAWKnOwqPd2IiB5D58yU98y/gLGjiukjiCr8EDFs=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=Nvj7mcvGZ+30ZxUvug23GrbFVML9KsM44FhzPopNJcUk1Pfv5gSDa4QyftKh722YE hk6UjlHqsWLD71WN3MJ6qXghu0RmqGyURxnEoEUX80WCmQowh92TGf/GACdo+zMJ3u /KgchqgaWnmQAhUnu8WwPz4Y2ogcJ4tWii1YwdKrbf3YQMJy+LuUlsAUbQuYNo+TNC v/552f8/D6sjYV6InqAq+EltZUjOiYRuFKOYl1FMeoADRR25/VLDi4/4v0zpM/jjXo 1ZFmrY6e/M5khx2t+LrjWK0TxB8CKYxODyLODxvRqq8+V1UkZ8vvKG7Uyph1ZUUVA/ lVCblWcqgUMxQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x6TLYVji2941384; Mon, 29 Jul 2019 14:34:31 -0700 Date: Mon, 29 Jul 2019 14:34:31 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Vince Weaver Message-ID: Cc: linux-kernel@vger.kernel.org, vincent.weaver@maine.edu, mingo@kernel.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, hpa@zytor.com, acme@redhat.com, namhyung@kernel.org, tglx@linutronix.de, jolsa@redhat.com Reply-To: tglx@linutronix.de, jolsa@redhat.com, namhyung@kernel.org, peterz@infradead.org, acme@redhat.com, hpa@zytor.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, vincent.weaver@maine.edu In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf header: Fix divide by zero error if f_header.attr_size==0 Git-Commit-ID: 7622236ceb167aa3857395f9bdaf871442aa467e 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: 7622236ceb167aa3857395f9bdaf871442aa467e Gitweb: https://git.kernel.org/tip/7622236ceb167aa3857395f9bdaf871442aa467e Author: Vince Weaver AuthorDate: Tue, 23 Jul 2019 11:06:01 -0400 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 29 Jul 2019 09:03:43 -0300 perf header: Fix divide by zero error if f_header.attr_size==0 So I have been having lots of trouble with hand-crafted perf.data files causing segfaults and the like, so I have started fuzzing the perf tool. First issue found: If f_header.attr_size is 0 in the perf.data file, then perf will crash with a divide-by-zero error. Committer note: Added a pr_err() to tell the user why the command failed. Signed-off-by: Vince Weaver Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/alpine.DEB.2.21.1907231100440.14532@macbook-air Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/header.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 20111f8da5cb..47877f0f6667 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3559,6 +3559,13 @@ int perf_session__read_header(struct perf_session *session) data->file.path); } + if (f_header.attr_size == 0) { + pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n" + "Was the 'perf record' command properly terminated?\n", + data->file.path); + return -EINVAL; + } + nr_attrs = f_header.attrs.size / f_header.attr_size; lseek(fd, f_header.attrs.offset, SEEK_SET);