linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Vince Weaver <vincent.weaver@maine.edu>
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>
Subject: Re: [patch] perf tool divide by zero error if f_header.attr_size==0
Date: Fri, 26 Jul 2019 16:00:16 -0300	[thread overview]
Message-ID: <20190726190016.GB20482@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.21.1907231100440.14532@macbook-air>

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 <vincent.weaver@maine.edu>


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

  parent reply	other threads:[~2019-07-26 19:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 15:06 [patch] perf tool divide by zero error if f_header.attr_size==0 Vince Weaver
2019-07-23 15:17 ` Arnaldo Carvalho de Melo
2019-07-23 20:42 ` [patch] perf tool buffer overflow in perf_header__read_build_ids Vince Weaver
2019-07-26 19:05   ` Arnaldo Carvalho de Melo
2019-08-23 20:42     ` Vince Weaver
2019-08-25 14:33       ` Arnaldo Carvalho de Melo
2019-07-26 19:00 ` Arnaldo Carvalho de Melo [this message]
2019-07-29 21:34 ` [tip:perf/urgent] perf header: Fix divide by zero error if f_header.attr_size==0 tip-bot for Vince Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190726190016.GB20482@kernel.org \
    --to=arnaldo.melo@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=vincent.weaver@maine.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).