From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf buildid: fix off-by-one in write_buildid()
Date: Tue, 19 Apr 2016 18:48:43 +0300 [thread overview]
Message-ID: <5716535B.9020800@virtuozzo.com> (raw)
In-Reply-To: <20160419133841.GB3677@kernel.org>
On 04/19/2016 04:38 PM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Apr 19, 2016 at 11:17:27AM +0300, Andrey Ryabinin escreveu:
>> write_buildid() increments 'name_len' with intention to take into account
>> trailing zero byte. However, 'name_len' was already incremented in
>> machine__write_buildid_table() before.
>> So this leads to out-of-bounds read in do_write():
>
> Could we keep the assumptions that for a string 's' the length is
> strlen(s) and that when we want to write a string _with_ its trailing
> '\0' we should use strlen(s) + 1?
>
> I.e. I propose this patch instead, ok?
>
Yup, looks good. Thanks.
> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 0573c2ec861d..b6ecf87bc3e3 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -261,14 +261,14 @@ static int machine__write_buildid_table(struct machine *machine, int fd)
>
> if (dso__is_vdso(pos)) {
> name = pos->short_name;
> - name_len = pos->short_name_len + 1;
> + name_len = pos->short_name_len;
> } else if (dso__is_kcore(pos)) {
> machine__mmap_name(machine, nm, sizeof(nm));
> name = nm;
> - name_len = strlen(nm) + 1;
> + name_len = strlen(nm);
> } else {
> name = pos->long_name;
> - name_len = pos->long_name_len + 1;
> + name_len = pos->long_name_len;
> }
>
> in_kernel = pos->kernel ||
>
next prev parent reply other threads:[~2016-04-19 15:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-19 8:17 [PATCH] perf buildid: fix off-by-one in write_buildid() Andrey Ryabinin
2016-04-19 13:38 ` Arnaldo Carvalho de Melo
2016-04-19 15:48 ` Andrey Ryabinin [this message]
2016-04-19 13:40 ` Arnaldo Carvalho de Melo
2016-04-20 12:36 ` Adrian Hunter
2016-04-20 13:23 ` Arnaldo Carvalho de Melo
2016-04-27 15:28 ` [tip:perf/core] perf buildid: Fix " tip-bot for Andrey Ryabinin
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=5716535B.9020800@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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.