All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Mitchell Krome <mitchellkrome@gmail.com>
Cc: acme@kernel.org, mingo@redhat.com, paulus@samba.org,
	a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf tool: Fix use after free in filename__read_build_id
Date: Tue, 16 Dec 2014 16:35:23 +0100	[thread overview]
Message-ID: <20141216153523.GA19086@krava.brq.redhat.com> (raw)
In-Reply-To: <20141216021612.GA7199@mitchell>

On Tue, Dec 16, 2014 at 12:16:12PM +1000, Mitchell Krome wrote:
> In filename__read_build_id, phdr points to memory in buf, which gets realloced
> before a call to fseek that uses phdr->p_offset. This change stores the value
> of p_offset before buf is realloced, so the fseek can use the value safely.
> 
> Signed-off-by: Mitchell Krome <mitchellkrome@gmail.com>
> ---
>  tools/perf/util/symbol-minimal.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c
> index fa585c6..d7efb03 100644
> --- a/tools/perf/util/symbol-minimal.c
> +++ b/tools/perf/util/symbol-minimal.c
> @@ -129,6 +129,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
>  
>  		for (i = 0, phdr = buf; i < ehdr.e_phnum; i++, phdr++) {
>  			void *tmp;
> +			long offset;
>  
>  			if (need_swap) {
>  				phdr->p_type = bswap_32(phdr->p_type);
> @@ -140,12 +141,13 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
>  				continue;
>  
>  			buf_size = phdr->p_filesz;
> +			offset = phdr->p_offset;
>  			tmp = realloc(buf, buf_size);
>  			if (tmp == NULL)
>  				goto out_free;
>  
>  			buf = tmp;
> -			fseek(fp, phdr->p_offset, SEEK_SET);
> +			fseek(fp, offset, SEEK_SET);

so the concern is that the realloc buf_size will be smaller
than the 'buf' offset of phdr->p_offset value, right? Anyway:

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

  reply	other threads:[~2014-12-16 15:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-16  2:16 [PATCH] perf tool: Fix use after free in filename__read_build_id Mitchell Krome
2014-12-16 15:35 ` Jiri Olsa [this message]
2014-12-16 16:34   ` Arnaldo Carvalho de Melo
2014-12-18  6:33 ` [tip:perf/urgent] perf symbols: " tip-bot for Mitchell Krome

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=20141216153523.GA19086@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mitchellkrome@gmail.com \
    --cc=paulus@samba.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.