Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp465932ybi; Fri, 26 Jul 2019 12:52:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2/2DrHXjKUG5Eo818VDumHf8u6sAJmgrSFRuR+hYZXxJJF9O//nUOXczeWNSWXgZWntzj X-Received: by 2002:a63:550e:: with SMTP id j14mr8498273pgb.302.1564170734229; Fri, 26 Jul 2019 12:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564170734; cv=none; d=google.com; s=arc-20160816; b=pm+MmUVppxQStpe+IZHHuxHVviCpvnbarswu7hPU87SGmJk7NXVnz5Hx6PYmSVCO/9 3kIbBSZEwqW186YO2IMATdYcIiFU90v/gjs0k8iU7WkWm0w8Z6GwErZq4o7DFNJAxJE/ /zha6aC49kBu5gIh1W72Aw8G+oP0BqjdNmWcgfWhnDDfQZuhyXJEJvKXyAolPbu/ygYj j63sM+fIOB9Brfegp6j/RtFH3c//mgFePvg3aRBCzpQv9+zpnrk7d100eJzyNoPb6XmJ Sp8fcc1CIFaB8XFxTSrwzeuTpHqJY/U07fi24PY/IlLKmfbrBi7+Lgv6OG87A0YUmxYk 9EeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=pl5ZN1tIu5/f+o27SPQ4FfIyyDR7u8qs0vTKkb7CN1M=; b=YUml0vwl4wpOjHVSnl13Q83BoyC/+7ZK4dSp2zbglbVmpC28fgSIw89apXCgoBSxAi 6TDoqTKNzlorwAQJtnMDhrkVpYcdCdKMss45cEobGAaQcbnhBy2k5qSTnh33hk3C8SKK 7YTZ160inR3l8T+V4l2QdXwIChL9IUHeoU0PDnsw2J0RRTxVAxkfOq4ddyeDZiHPvFhU HBT+sWAhfKJdk3q0xhqlvAyqeAvEaBLW+fr8ecJ+9+E/btd0pCcvQkq0B0ZQ5zbn/FIv TKJnJnay95dPX60GHC5OGMzADeiPXujzbWDp2fNHfuu5Y8BuKRGDLVRgmYYNwgj9p2q/ 9GMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pFp5IHLH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si21135166pfi.264.2019.07.26.12.51.59; Fri, 26 Jul 2019 12:52:14 -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=@gmail.com header.s=20161025 header.b=pFp5IHLH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388302AbfGZTAX (ORCPT + 99 others); Fri, 26 Jul 2019 15:00:23 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:42146 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387743AbfGZTAW (ORCPT ); Fri, 26 Jul 2019 15:00:22 -0400 Received: by mail-qk1-f196.google.com with SMTP id 201so39805046qkm.9 for ; Fri, 26 Jul 2019 12:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pl5ZN1tIu5/f+o27SPQ4FfIyyDR7u8qs0vTKkb7CN1M=; b=pFp5IHLHW8CTyLie7a8MsAEoDNc93Am5xK3dtCwExeles2LhWiQW8xrxwrHSEFqJWG ecSJFgJttfSutkNyJDbDf9QTbwlbabzeO15afanO6IoLbA4opfIQxeEKTofX+oP7qF0H 42P0u4FcWU0TtHauixXj+EefF04hTppV525N7MIUjXrRw2T+m5LQmsBHUpfmdU43OOSX 3ZdWytU14AaIuX3WNP8kQzyIfPm7UV9UwZsu6xIhUSOU7gwR1xDg3+lwLJNvvoNOhiw8 P1tlWEwYzjBG9stoHsjsoibXlap8iuhmDrpqDEtUS8rekUXQn6Pgg8hKTkOT+vOtLyWg PsuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pl5ZN1tIu5/f+o27SPQ4FfIyyDR7u8qs0vTKkb7CN1M=; b=Z6/Qrd69jpeBjOhzdG2BzBGTtjWDvbuyBrhLHSTtQ7HjVQe6u9tf/vFCwHefzEdVlR r4ng8Q3x3rDqtZHjY7M5PtY2NM8VXVAxw+H96OP7tbYC4qsouUYepOnoxFqhVCM6df9G tBvyJkBvROCjWb7+0FKwbfkhDlhGh9AU4b10h27Oqr8tCAShGaLwzQ1wPdweJvksm/uM rXMdw1Bq1dXx10Z2QXPsUUXzRv4DZ9mbTD8BXGtiUEiFmAHnWOiiulYDNcl4oLqb4j7W XDzeS9E8eyHA5mBT+i2vmSs1AsHuVzZ5DagEdh6ul3AZ0oXYclTXRZKfbZ/QOXpK9Zcc xTIQ== X-Gm-Message-State: APjAAAWcROcUAc9lvikojKo1eq11yIDqnNvhIKGILnS5PctINCvt70Jf bkzIQRbO7gsdFCXCKJ3u9B4= X-Received: by 2002:a37:648:: with SMTP id 69mr64381529qkg.248.1564167621387; Fri, 26 Jul 2019 12:00:21 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id o10sm27071131qti.62.2019.07.26.12.00.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 12:00:19 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 8561F40340; Fri, 26 Jul 2019 16:00:16 -0300 (-03) Date: Fri, 26 Jul 2019 16:00:16 -0300 To: Vince Weaver Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: Re: [patch] perf tool divide by zero error if f_header.attr_size==0 Message-ID: <20190726190016.GB20482@kernel.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Jul 23, 2019 at 11:06:01AM -0400, Vince Weaver escreveu: > Hello > > 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. > > Signed-off-by: Vince Weaver I added this on top: diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 25f89d0790fe..47877f0f6667 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3560,6 +3560,9 @@ int perf_session__read_header(struct perf_session *session) } 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; } [acme@quaco perf]$ Thanks, applied. - Arnaldo > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index c24db7f4909c..26df60ee9460 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -3559,6 +3559,10 @@ int perf_session__read_header(struct perf_session *session) > data->file.path); > } > > + if (f_header.attr_size == 0) { > + return -EINVAL; > + } > + > nr_attrs = f_header.attrs.size / f_header.attr_size; > lseek(fd, f_header.attrs.offset, SEEK_SET); > -- - Arnaldo