* [PATCH 0/5] Allow syscalls tracepoints to non privileged users
@ 2010-11-18 1:32 Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 1/5] tracing: New flag to allow non privileged users to use a trace event Frederic Weisbecker
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
Hi,
Tell me if you're fine with it, and if so I'll push it.
Thanks.
Frederic Weisbecker (5):
tracing: New flag to allow non privileged users to use a trace event
tracing: New macro to set up initial event flags value
tracing: Allow raw syscall trace events for non privileged users
tracing: Allow syscall trace events for non privileged users
tracing: Remove useless syscall ftrace_event_call declaration
include/linux/ftrace_event.h | 10 ++++++++++
include/linux/syscalls.h | 10 ++++------
include/linux/tracepoint.h | 4 ++++
include/trace/events/syscalls.h | 4 ++++
include/trace/ftrace.h | 7 +++++++
kernel/perf_event.c | 9 ---------
kernel/trace/trace_event_perf.c | 31 ++++++++++++++++++++++++++++++-
7 files changed, 59 insertions(+), 16 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] tracing: New flag to allow non privileged users to use a trace event
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
@ 2010-11-18 1:32 ` Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 2/5] tracing: New macro to set up initial event flags value Frederic Weisbecker
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
This adds a new trace event internal flag that allows them to be
used in perf by non privileged users in case of task bound tracing.
This is desired for syscalls tracepoint because they don't leak
global system informations, like some other tracepoints.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
---
include/linux/ftrace_event.h | 2 ++
kernel/perf_event.c | 9 ---------
kernel/trace/trace_event_perf.c | 31 ++++++++++++++++++++++++++++++-
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 8beabb9..312dce7 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -154,12 +154,14 @@ enum {
TRACE_EVENT_FL_ENABLED_BIT,
TRACE_EVENT_FL_FILTERED_BIT,
TRACE_EVENT_FL_RECORDED_CMD_BIT,
+ TRACE_EVENT_FL_CAP_ANY_BIT,
};
enum {
TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT),
TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
TRACE_EVENT_FL_RECORDED_CMD = (1 << TRACE_EVENT_FL_RECORDED_CMD_BIT),
+ TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
};
struct ftrace_event_call {
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 517d827..ee1e903 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -4747,15 +4747,6 @@ static int perf_tp_event_init(struct perf_event *event)
if (event->attr.type != PERF_TYPE_TRACEPOINT)
return -ENOENT;
- /*
- * Raw tracepoint data is a severe data leak, only allow root to
- * have these.
- */
- if ((event->attr.sample_type & PERF_SAMPLE_RAW) &&
- perf_paranoid_tracepoint_raw() &&
- !capable(CAP_SYS_ADMIN))
- return -EPERM;
-
err = perf_trace_init(event);
if (err)
return err;
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 39c059c..19a359d 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -21,17 +21,46 @@ typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)])
/* Count the events in use (per event id, not per instance) */
static int total_ref_count;
+static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
+ struct perf_event *p_event)
+{
+ /* No tracing, just counting, so no obvious leak */
+ if (!(p_event->attr.sample_type & PERF_SAMPLE_RAW))
+ return 0;
+
+ /* Some events are ok to be traced by non-root users... */
+ if (p_event->attach_state == PERF_ATTACH_TASK) {
+ if (tp_event->flags & TRACE_EVENT_FL_CAP_ANY)
+ return 0;
+ }
+
+ /*
+ * ...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;
+
+ return 0;
+}
+
static int perf_trace_event_init(struct ftrace_event_call *tp_event,
struct perf_event *p_event)
{
struct hlist_head __percpu *list;
- int ret = -ENOMEM;
+ int ret;
int cpu;
+ ret = perf_trace_event_perm(tp_event, p_event);
+ if (ret)
+ return ret;
+
p_event->tp_event = tp_event;
if (tp_event->perf_refcount++ > 0)
return 0;
+ ret = -ENOMEM;
+
list = alloc_percpu(struct hlist_head);
if (!list)
goto fail;
--
1.6.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] tracing: New macro to set up initial event flags value
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 1/5] tracing: New flag to allow non privileged users to use a trace event Frederic Weisbecker
@ 2010-11-18 1:32 ` Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 3/5] tracing: Allow raw syscall trace events for non privileged users Frederic Weisbecker
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
This introduces the new TRACE_EVENT_FLAGS() macro in order
to set up initial event flags value.
This macro must simply follow the definition of a trace event
and take the event name and the flag value as parameters:
TRACE_EVENT(my_event, .....
....
);
TRACE_EVENT_FLAGS(my_event, 1)
This will set up 1 as the initial my_event->flags value.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
---
include/linux/tracepoint.h | 4 ++++
include/trace/ftrace.h | 12 ++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index a4a90b6..5a6074f 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -234,6 +234,8 @@ do_trace: \
PARAMS(void *__data, proto), \
PARAMS(__data, args))
+#define TRACE_EVENT_FLAGS(event, flag)
+
#endif /* DECLARE_TRACE */
#ifndef TRACE_EVENT
@@ -354,4 +356,6 @@ do_trace: \
assign, print, reg, unreg) \
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_FLAGS(event, flag)
+
#endif /* ifdef TRACE_EVENT (see note above) */
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index a9377c0..6f54012 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -82,6 +82,15 @@
TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
+#undef TRACE_EVENT_FLAGS
+#define TRACE_EVENT_FLAGS(name, value) \
+ static int __init trace_init_flags_##name(void) \
+ { \
+ event_##name.flags = value; \
+ return 0; \
+ } \
+ early_initcall(trace_init_flags_##name);
+
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
@@ -129,6 +138,9 @@
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
+#undef TRACE_EVENT_FLAGS
+#define TRACE_EVENT_FLAGS(event, flag)
+
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
/*
--
1.6.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] tracing: Allow raw syscall trace events for non privileged users
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 1/5] tracing: New flag to allow non privileged users to use a trace event Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 2/5] tracing: New macro to set up initial event flags value Frederic Weisbecker
@ 2010-11-18 1:32 ` Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 4/5] tracing: Allow " Frederic Weisbecker
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
This allows non privileged users to use the raw syscall trace events
for task bound tracing in perf.
It is safe because raw syscall trace events don't leak system wide
informations.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
---
include/trace/events/syscalls.h | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/include/trace/events/syscalls.h b/include/trace/events/syscalls.h
index fb726ac..5a4c04a 100644
--- a/include/trace/events/syscalls.h
+++ b/include/trace/events/syscalls.h
@@ -40,6 +40,8 @@ TRACE_EVENT_FN(sys_enter,
syscall_regfunc, syscall_unregfunc
);
+TRACE_EVENT_FLAGS(sys_enter, TRACE_EVENT_FL_CAP_ANY)
+
TRACE_EVENT_FN(sys_exit,
TP_PROTO(struct pt_regs *regs, long ret),
@@ -62,6 +64,8 @@ TRACE_EVENT_FN(sys_exit,
syscall_regfunc, syscall_unregfunc
);
+TRACE_EVENT_FLAGS(sys_exit, TRACE_EVENT_FL_CAP_ANY)
+
#endif /* CONFIG_HAVE_SYSCALL_TRACEPOINTS */
#endif /* _TRACE_EVENTS_SYSCALLS_H */
--
1.6.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] tracing: Allow syscall trace events for non privileged users
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
` (2 preceding siblings ...)
2010-11-18 1:32 ` [PATCH 3/5] tracing: Allow raw syscall trace events for non privileged users Frederic Weisbecker
@ 2010-11-18 1:32 ` Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 5/5] tracing: Remove useless syscall ftrace_event_call declaration Frederic Weisbecker
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
As for the raw syscalls events, individual syscall events won't
leak system wide information on task bound tracing. Allow non
privileged users to use them in such workflow.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
---
include/linux/ftrace_event.h | 8 ++++++++
include/linux/syscalls.h | 6 ++++--
include/trace/ftrace.h | 7 +------
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 312dce7..725bf6b 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -198,6 +198,14 @@ struct ftrace_event_call {
#endif
};
+#define __TRACE_EVENT_FLAGS(name, value) \
+ static int __init trace_init_flags_##name(void) \
+ { \
+ event_##name.flags = value; \
+ return 0; \
+ } \
+ early_initcall(trace_init_flags_##name);
+
#define PERF_MAX_TRACE_SIZE 2048
#define MAX_FILTER_PRED 32
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index cacc27a..13b9731 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -137,7 +137,8 @@ extern struct trace_event_functions exit_syscall_print_funcs;
.class = &event_class_syscall_enter, \
.event.funcs = &enter_syscall_print_funcs, \
.data = (void *)&__syscall_meta_##sname,\
- }
+ }; \
+ __TRACE_EVENT_FLAGS(enter_##sname, TRACE_EVENT_FL_CAP_ANY)
#define SYSCALL_TRACE_EXIT_EVENT(sname) \
static struct syscall_metadata \
@@ -152,7 +153,8 @@ extern struct trace_event_functions exit_syscall_print_funcs;
.class = &event_class_syscall_exit, \
.event.funcs = &exit_syscall_print_funcs, \
.data = (void *)&__syscall_meta_##sname,\
- }
+ }; \
+ __TRACE_EVENT_FLAGS(exit_##sname, TRACE_EVENT_FL_CAP_ANY)
#define SYSCALL_METADATA(sname, nb) \
SYSCALL_TRACE_ENTER_EVENT(sname); \
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 6f54012..e718a91 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -84,12 +84,7 @@
#undef TRACE_EVENT_FLAGS
#define TRACE_EVENT_FLAGS(name, value) \
- static int __init trace_init_flags_##name(void) \
- { \
- event_##name.flags = value; \
- return 0; \
- } \
- early_initcall(trace_init_flags_##name);
+ __TRACE_EVENT_FLAGS(name, value)
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
--
1.6.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] tracing: Remove useless syscall ftrace_event_call declaration
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
` (3 preceding siblings ...)
2010-11-18 1:32 ` [PATCH 4/5] tracing: Allow " Frederic Weisbecker
@ 2010-11-18 1:32 ` Frederic Weisbecker
2010-11-18 8:19 ` [PATCH 0/5] Allow syscalls tracepoints to non privileged users Ingo Molnar
2010-11-18 8:56 ` Peter Zijlstra
6 siblings, 0 replies; 8+ messages in thread
From: Frederic Weisbecker @ 2010-11-18 1:32 UTC (permalink / raw)
To: Ingo Molnar
Cc: LKML, Frederic Weisbecker, Ingo Molnar, Peter Zijlstra,
Arnaldo Carvalho de Melo, Thomas Gleixner, Steven Rostedt,
Li Zefan, Jason Baron
It is defined right after, which makes the declaration completely
useless.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
---
include/linux/syscalls.h | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 13b9731..18cd068 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -127,8 +127,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;
#define SYSCALL_TRACE_ENTER_EVENT(sname) \
static struct syscall_metadata \
__attribute__((__aligned__(4))) __syscall_meta_##sname; \
- static struct ftrace_event_call \
- __attribute__((__aligned__(4))) event_enter_##sname; \
static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \
@@ -143,8 +141,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;
#define SYSCALL_TRACE_EXIT_EVENT(sname) \
static struct syscall_metadata \
__attribute__((__aligned__(4))) __syscall_meta_##sname; \
- static struct ftrace_event_call \
- __attribute__((__aligned__(4))) event_exit_##sname; \
static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \
--
1.6.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/5] Allow syscalls tracepoints to non privileged users
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
` (4 preceding siblings ...)
2010-11-18 1:32 ` [PATCH 5/5] tracing: Remove useless syscall ftrace_event_call declaration Frederic Weisbecker
@ 2010-11-18 8:19 ` Ingo Molnar
2010-11-18 8:56 ` Peter Zijlstra
6 siblings, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2010-11-18 8:19 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: LKML, Peter Zijlstra, Arnaldo Carvalho de Melo, Thomas Gleixner,
Steven Rostedt, Li Zefan, Jason Baron
* Frederic Weisbecker <fweisbec@gmail.com> wrote:
> Hi,
>
> Tell me if you're fine with it, and if so I'll push it.
Yeah, very nice work!
Thanks,
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/5] Allow syscalls tracepoints to non privileged users
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
` (5 preceding siblings ...)
2010-11-18 8:19 ` [PATCH 0/5] Allow syscalls tracepoints to non privileged users Ingo Molnar
@ 2010-11-18 8:56 ` Peter Zijlstra
6 siblings, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2010-11-18 8:56 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: Ingo Molnar, LKML, Arnaldo Carvalho de Melo, Thomas Gleixner,
Steven Rostedt, Li Zefan, Jason Baron
On Thu, 2010-11-18 at 02:32 +0100, Frederic Weisbecker wrote:
> Hi,
>
> Tell me if you're fine with it, and if so I'll push it.
Looks good to me, thanks!
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-11-18 8:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-18 1:32 [PATCH 0/5] Allow syscalls tracepoints to non privileged users Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 1/5] tracing: New flag to allow non privileged users to use a trace event Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 2/5] tracing: New macro to set up initial event flags value Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 3/5] tracing: Allow raw syscall trace events for non privileged users Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 4/5] tracing: Allow " Frederic Weisbecker
2010-11-18 1:32 ` [PATCH 5/5] tracing: Remove useless syscall ftrace_event_call declaration Frederic Weisbecker
2010-11-18 8:19 ` [PATCH 0/5] Allow syscalls tracepoints to non privileged users Ingo Molnar
2010-11-18 8:56 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox