From: Jiri Olsa <jolsa@redhat.com>
To: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
Christian Borntraeger <borntraeger@de.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [BUG] perf stat: events inheritance can break task targets
Date: Mon, 7 Jul 2014 19:00:40 +0200 [thread overview]
Message-ID: <20140707170040.GB2070@krava.redhat.com> (raw)
In-Reply-To: <874myt86ju.wl%yarygin@linux.vnet.ibm.com>
On Mon, Jul 07, 2014 at 08:41:57PM +0400, Alexander Yarygin wrote:
SNIP
> ^C
>
> When perf is running, every invoke of pthread_create() returns -EPERM.
>
> On the kernel side, copy_process() creates a task, scheduled it,
> than perf_event_init_task() (kernel/events/core.c) returns an error,
> and the kernel cleans task's resources.
>
> It looks like child process doesn't have access to trace events,
> so perf_trace_event_perm() (kernel/trace/trace_event_perf.c)
> returns -EPERM:
>
> static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
> struct perf_event *p_event)
> {
> ...
> /*
> * ...otherwise raw tracepoint data can be a severe data leak,
> * only allow root to have these.
> */
> if (perf_paranoid_tracepoint_raw() && !capable(CAP_SYS_ADMIN))
> return -EPERM;
> ...
> }
right, so normaly it's done the check is done in current context
via syscall and the current task is the tracer
while in inheriting we are checking the tracee here,
we want to check the owner instead like in attached
patch.. totaly untested, just to ilustrate the point
we might have same issue for other event types
jirka
---
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 5d12bb4..b44184b 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -24,6 +24,9 @@ static int total_ref_count;
static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
struct perf_event *p_event)
{
+ struct task_struct owner = p_event->parent ? p_event->parent->owner :
+ p_event->owner;
+
if (tp_event->perf_perm) {
int ret = tp_event->perf_perm(tp_event, p_event);
if (ret)
@@ -32,7 +35,7 @@ static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
/* The ftrace function trace is allowed only for root. */
if (ftrace_event_is_function(tp_event)) {
- if (perf_paranoid_tracepoint_raw() && !capable(CAP_SYS_ADMIN))
+ if (perf_paranoid_tracepoint_raw() && !has_capability(owner, CAP_SYS_ADMIN))
return -EPERM;
/*
@@ -65,7 +68,7 @@ static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
* ...otherwise raw tracepoint data can be a severe data leak,
* only allow root to have these.
*/
- if (perf_paranoid_tracepoint_raw() && !capable(CAP_SYS_ADMIN))
+ if (perf_paranoid_tracepoint_raw() && !has_capability(owner, CAP_SYS_ADMIN))
return -EPERM;
return 0;
next prev parent reply other threads:[~2014-07-07 17:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 16:41 [BUG] perf stat: events inheritance can break task targets Alexander Yarygin
2014-07-07 17:00 ` Jiri Olsa [this message]
2014-07-07 19:46 ` Peter Zijlstra
2014-07-08 6:59 ` Jiri Olsa
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=20140707170040.GB2070@krava.redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.com \
--cc=borntraeger@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulus@samba.org \
--cc=yarygin@linux.vnet.ibm.com \
/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