From: Peter Zijlstra <peterz@infradead.org>
To: Vince Weaver <vincent.weaver@maine.edu>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: perf: bug, kernel ignores the buffer size on large read
Date: Thu, 3 Sep 2015 01:08:04 +0200 [thread overview]
Message-ID: <20150902230804.GX19282@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1509021227380.32729@vincent-weaver-1.umelst.maine.edu>
On Wed, Sep 02, 2015 at 12:34:41PM -0400, Vince Weaver wrote:
>
> OK, this time I found the actual bug.
>
> event->read_size is declared as a u16 in include/linux/perf_event.h
>
> but it is very easy to get event->read_size larger than 64k
> (in my case, create 10000 events in a group).
>
> Because we wrap around the u16, the
> if (count < event->read_size) return -ENOSPC;
> in perf_read_hw() doesn't trigger reliably and so if you do a read
> on a large group event the kernel will quite happily copy_to_user()
> beyond the bounds of the value set in the read syscall.
>
> In my case it completely smashed the stack and caused the program to
> segfault.
>
> I'm not sure what the solution is here. Change read_size to be larger?
> Ban events whose read size would be larger than 64k? Although that gets
> tricky because the related header_size is also only a u16.
I think we should try and just ban events with a read_size > 64k; that's
one _large_ group -- there's other issues with that as well I imagine.
If we really want to allow something larger, we _could_ fudge something
for cases where we do not have PERF_SAMPLE_READ set, but that's not
particularly nice either.
next prev parent reply other threads:[~2015-09-02 23:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-02 16:34 Vince Weaver
2015-09-02 23:08 ` Peter Zijlstra [this message]
2015-09-03 2:32 ` 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=20150902230804.GX19282@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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
Powered by JetHome