linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Trace event for capable().
@ 2012-05-17 19:50 Auke Kok
  2012-05-18 22:25 ` Serge Hallyn
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Auke Kok @ 2012-05-17 19:50 UTC (permalink / raw)
  To: Serge Hallyn; +Cc: Auke Kok, linux-security-module, linux-kernel, Eric Paris

Add a simple trace event for capable().

There's been a lot of discussion around capable(), and there
are plenty of tools to help reduce capabilities' usage from
userspace. A major gap however is that it's almost impossible
to see or verify which bits are requested from either userspace
or in the kernel.

This patch adds a minimal tracer that will print out which
CAPs are requested and whether the request was granted.

Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
Cc: linux-security-module@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Serge Hallyn <serge.hallyn@canonical.com>
Cc: Eric Paris <eparis@redhat.com>
---
 include/trace/events/capabilities.h |   33 +++++++++++++++++++++++++++++++++
 kernel/capability.c                 |    5 +++++
 2 files changed, 38 insertions(+)
 create mode 100644 include/trace/events/capabilities.h

diff --git a/include/trace/events/capabilities.h b/include/trace/events/capabilities.h
new file mode 100644
index 0000000..97997fa
--- /dev/null
+++ b/include/trace/events/capabilities.h
@@ -0,0 +1,33 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM capabilities
+
+#if !defined(_TRACE_CAPABILITIES_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_CAPABILITIES_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(capable,
+
+	TP_PROTO(pid_t pid, int cap, bool rc),
+
+	TP_ARGS(pid, cap, rc),
+
+	TP_STRUCT__entry(
+		__field(pid_t, pid)
+		__field(int, cap)
+		__field(bool, rc)
+	),
+
+	TP_fast_assign(
+		__entry->pid = pid;
+		__entry->cap = cap;
+		__entry->rc = rc;
+	),
+
+	TP_printk("pid=%d cap=%d rc=%d", __entry->pid, __entry->cap, __entry->rc)
+);
+
+#endif /* _TRACE_CAPABILITIES_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/kernel/capability.c b/kernel/capability.c
index 3f1adb6..2941f37 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -17,6 +17,9 @@
 #include <linux/user_namespace.h>
 #include <asm/uaccess.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/capabilities.h>
+
 /*
  * Leveraged for setting/resetting capabilities
  */
@@ -386,8 +389,10 @@ bool ns_capable(struct user_namespace *ns, int cap)
 
 	if (security_capable(current_cred(), ns, cap) == 0) {
 		current->flags |= PF_SUPERPRIV;
+		trace_capable(current->pid, cap, true);
 		return true;
 	}
+	trace_capable(current->pid, cap, false);
 	return false;
 }
 EXPORT_SYMBOL(ns_capable);
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-17 19:50 [PATCH] Trace event for capable() Auke Kok
@ 2012-05-18 22:25 ` Serge Hallyn
  2012-05-18 23:11   ` Kok, Auke-jan H
  2012-05-18 22:33 ` richard -rw- weinberger
  2012-05-19  6:59 ` Eric W. Biederman
  2 siblings, 1 reply; 12+ messages in thread
From: Serge Hallyn @ 2012-05-18 22:25 UTC (permalink / raw)
  To: Auke Kok; +Cc: linux-security-module, linux-kernel, Eric Paris

Quoting Auke Kok (auke-jan.h.kok@intel.com):
> Add a simple trace event for capable().
> 
> There's been a lot of discussion around capable(), and there
> are plenty of tools to help reduce capabilities' usage from
> userspace. A major gap however is that it's almost impossible
> to see or verify which bits are requested from either userspace
> or in the kernel.
> 
> This patch adds a minimal tracer that will print out which
> CAPs are requested and whether the request was granted.
> 
> Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
> Cc: linux-security-module@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: Serge Hallyn <serge.hallyn@canonical.com>

Hi,

is there any measurable performance impact by this patch?  (Have you
measured it?)

I'm not familiar enough with the tracing stuff, but if the tracing is
done so there's no impact when not tracing, then I have no problem with
this.  It could be quite useful as you say.

Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>

thanks,
-serge

> Cc: Eric Paris <eparis@redhat.com>
> ---
>  include/trace/events/capabilities.h |   33 +++++++++++++++++++++++++++++++++
>  kernel/capability.c                 |    5 +++++
>  2 files changed, 38 insertions(+)
>  create mode 100644 include/trace/events/capabilities.h
> 
> diff --git a/include/trace/events/capabilities.h b/include/trace/events/capabilities.h
> new file mode 100644
> index 0000000..97997fa
> --- /dev/null
> +++ b/include/trace/events/capabilities.h
> @@ -0,0 +1,33 @@
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM capabilities
> +
> +#if !defined(_TRACE_CAPABILITIES_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_CAPABILITIES_H
> +
> +#include <linux/tracepoint.h>
> +
> +TRACE_EVENT(capable,
> +
> +	TP_PROTO(pid_t pid, int cap, bool rc),
> +
> +	TP_ARGS(pid, cap, rc),
> +
> +	TP_STRUCT__entry(
> +		__field(pid_t, pid)
> +		__field(int, cap)
> +		__field(bool, rc)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->pid = pid;
> +		__entry->cap = cap;
> +		__entry->rc = rc;
> +	),
> +
> +	TP_printk("pid=%d cap=%d rc=%d", __entry->pid, __entry->cap, __entry->rc)
> +);
> +
> +#endif /* _TRACE_CAPABILITIES_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> diff --git a/kernel/capability.c b/kernel/capability.c
> index 3f1adb6..2941f37 100644
> --- a/kernel/capability.c
> +++ b/kernel/capability.c
> @@ -17,6 +17,9 @@
>  #include <linux/user_namespace.h>
>  #include <asm/uaccess.h>
>  
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/capabilities.h>
> +
>  /*
>   * Leveraged for setting/resetting capabilities
>   */
> @@ -386,8 +389,10 @@ bool ns_capable(struct user_namespace *ns, int cap)
>  
>  	if (security_capable(current_cred(), ns, cap) == 0) {
>  		current->flags |= PF_SUPERPRIV;
> +		trace_capable(current->pid, cap, true);
>  		return true;
>  	}
> +	trace_capable(current->pid, cap, false);
>  	return false;
>  }
>  EXPORT_SYMBOL(ns_capable);
> -- 
> 1.7.10
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-17 19:50 [PATCH] Trace event for capable() Auke Kok
  2012-05-18 22:25 ` Serge Hallyn
@ 2012-05-18 22:33 ` richard -rw- weinberger
  2012-05-18 23:09   ` Kok, Auke-jan H
  2012-05-19  6:59 ` Eric W. Biederman
  2 siblings, 1 reply; 12+ messages in thread
From: richard -rw- weinberger @ 2012-05-18 22:33 UTC (permalink / raw)
  To: Auke Kok; +Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

On Thu, May 17, 2012 at 9:50 PM, Auke Kok <auke-jan.h.kok@intel.com> wrote:
> Add a simple trace event for capable().
>
> There's been a lot of discussion around capable(), and there
> are plenty of tools to help reduce capabilities' usage from
> userspace. A major gap however is that it's almost impossible
> to see or verify which bits are requested from either userspace
> or in the kernel.
>
> This patch adds a minimal tracer that will print out which
> CAPs are requested and whether the request was granted.

Can we please have support for user namespaces?
At least idicate whether the current namespace is init_user_ns or not.

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-18 22:33 ` richard -rw- weinberger
@ 2012-05-18 23:09   ` Kok, Auke-jan H
  2012-05-18 23:19     ` Serge Hallyn
  0 siblings, 1 reply; 12+ messages in thread
From: Kok, Auke-jan H @ 2012-05-18 23:09 UTC (permalink / raw)
  To: richard -rw- weinberger
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

On Fri, May 18, 2012 at 3:33 PM, richard -rw- weinberger
<richard.weinberger@gmail.com> wrote:
>
> On Thu, May 17, 2012 at 9:50 PM, Auke Kok <auke-jan.h.kok@intel.com>
> wrote:
> > Add a simple trace event for capable().
> >
> > There's been a lot of discussion around capable(), and there
> > are plenty of tools to help reduce capabilities' usage from
> > userspace. A major gap however is that it's almost impossible
> > to see or verify which bits are requested from either userspace
> > or in the kernel.
> >
> > This patch adds a minimal tracer that will print out which
> > CAPs are requested and whether the request was granted.
>
> Can we please have support for user namespaces?
> At least idicate whether the current namespace is init_user_ns or not.

that was the main reason for sending this out already - that should be
trivial to add to the trace event, but I haven't looked at namespaces
yet myself. I'll check it out.

Auke

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-18 22:25 ` Serge Hallyn
@ 2012-05-18 23:11   ` Kok, Auke-jan H
  0 siblings, 0 replies; 12+ messages in thread
From: Kok, Auke-jan H @ 2012-05-18 23:11 UTC (permalink / raw)
  To: Serge Hallyn; +Cc: linux-security-module, linux-kernel, Eric Paris

On Fri, May 18, 2012 at 3:25 PM, Serge Hallyn
<serge.hallyn@canonical.com> wrote:
> Quoting Auke Kok (auke-jan.h.kok@intel.com):
>> Add a simple trace event for capable().
>>
>> There's been a lot of discussion around capable(), and there
>> are plenty of tools to help reduce capabilities' usage from
>> userspace. A major gap however is that it's almost impossible
>> to see or verify which bits are requested from either userspace
>> or in the kernel.
>>
>> This patch adds a minimal tracer that will print out which
>> CAPs are requested and whether the request was granted.
>>
>> Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
>> Cc: linux-security-module@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Cc: Serge Hallyn <serge.hallyn@canonical.com>
>
> Hi,
>
> is there any measurable performance impact by this patch?  (Have you
> measured it?)

I actually did a full OS boot test and didn't see a noticeable
difference - basically
 booted with init=/bin/bash, mount debugfs, start the tracer and then
exec /sbin/init...
It's anecdotal, but, given the use of this tracer should be more than
acceptable.

Of course, there is a small (nop - ~1 cycle) penalty to the tracepoint
even if tracing
is disabled, but the codepath should never be in any form of hotpath no matter
what, since any call to capable() will end up in LSM checks and audit
checks anyway.

> I'm not familiar enough with the tracing stuff, but if the tracing is
> done so there's no impact when not tracing, then I have no problem with
> this.  It could be quite useful as you say.
>
> Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>

thanks, - I might resend a new patch if I can add the namespace info
as per the other comment.

Auke

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-18 23:09   ` Kok, Auke-jan H
@ 2012-05-18 23:19     ` Serge Hallyn
  2012-05-20 13:10       ` Serge E. Hallyn
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Hallyn @ 2012-05-18 23:19 UTC (permalink / raw)
  To: Kok, Auke-jan H, richard -rw- weinberger
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris


----- Original message -----
> On Fri, May 18, 2012 at 3:33 PM, richard -rw- weinberger
> <richard.weinberger@gmail.com> wrote:
> > 
> > On Thu, May 17, 2012 at 9:50 PM, Auke Kok <auke-jan.h.kok@intel.com>
> > wrote:
> > > Add a simple trace event for capable().
> > > 
> > > There's been a lot of discussion around capable(), and there
> > > are plenty of tools to help reduce capabilities' usage from
> > > userspace. A major gap however is that it's almost impossible
> > > to see or verify which bits are requested from either userspace
> > > or in the kernel.
> > > 
> > > This patch adds a minimal tracer that will print out which
> > > CAPs are requested and whether the request was granted.
> > 
> > Can we please have support for user namespaces?
> > At least idicate whether the current namespace is init_user_ns or not.
> 
> that was the main reason for sending this out already - that should be
> trivial to add to the trace event, but I haven't looked at namespaces
> yet myself. I'll check it out.
> 

right, trivial to add, but either go through linux-next or wait for Eric's patchset to move from there to Linus' tree.  Print the from_kuid(&init_user_ns, current_uid()), and if not in init_user_ns then also print the ns creator and task uid in his own ns.

I don't think you need to do that right now.

> Auke
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel"
> in the body of a message to majordomo@vger.kernel.org
> More majordomo info at   http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at   http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-17 19:50 [PATCH] Trace event for capable() Auke Kok
  2012-05-18 22:25 ` Serge Hallyn
  2012-05-18 22:33 ` richard -rw- weinberger
@ 2012-05-19  6:59 ` Eric W. Biederman
  2012-05-19 18:39   ` Kok, Auke-jan H
  2 siblings, 1 reply; 12+ messages in thread
From: Eric W. Biederman @ 2012-05-19  6:59 UTC (permalink / raw)
  To: Auke Kok; +Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

Auke Kok <auke-jan.h.kok@intel.com> writes:

> Add a simple trace event for capable().
>
> There's been a lot of discussion around capable(), and there
> are plenty of tools to help reduce capabilities' usage from
> userspace. A major gap however is that it's almost impossible
> to see or verify which bits are requested from either userspace
> or in the kernel.
>
> This patch adds a minimal tracer that will print out which
> CAPs are requested and whether the request was granted.

A small comment assigned from the other issues.

current->pid for anything going to userspace is broken,
and in fact current->pid should be killed on of these days.

Which pid namespace is your tracer running in?

> Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
> Cc: linux-security-module@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: Serge Hallyn <serge.hallyn@canonical.com>
> Cc: Eric Paris <eparis@redhat.com>
> ---
>  include/trace/events/capabilities.h |   33 +++++++++++++++++++++++++++++++++
>  kernel/capability.c                 |    5 +++++
>  2 files changed, 38 insertions(+)
>  create mode 100644 include/trace/events/capabilities.h
>
> diff --git a/include/trace/events/capabilities.h b/include/trace/events/capabilities.h
> new file mode 100644
> index 0000000..97997fa
> --- /dev/null
> +++ b/include/trace/events/capabilities.h
> @@ -0,0 +1,33 @@
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM capabilities
> +
> +#if !defined(_TRACE_CAPABILITIES_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_CAPABILITIES_H
> +
> +#include <linux/tracepoint.h>
> +
> +TRACE_EVENT(capable,
> +
> +	TP_PROTO(pid_t pid, int cap, bool rc),
> +
> +	TP_ARGS(pid, cap, rc),
> +
> +	TP_STRUCT__entry(
> +		__field(pid_t, pid)
> +		__field(int, cap)
> +		__field(bool, rc)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->pid = pid;
> +		__entry->cap = cap;
> +		__entry->rc = rc;
> +	),
> +
> +	TP_printk("pid=%d cap=%d rc=%d", __entry->pid, __entry->cap, __entry->rc)
> +);
> +
> +#endif /* _TRACE_CAPABILITIES_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> diff --git a/kernel/capability.c b/kernel/capability.c
> index 3f1adb6..2941f37 100644
> --- a/kernel/capability.c
> +++ b/kernel/capability.c
> @@ -17,6 +17,9 @@
>  #include <linux/user_namespace.h>
>  #include <asm/uaccess.h>
>  
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/capabilities.h>
> +
>  /*
>   * Leveraged for setting/resetting capabilities
>   */
> @@ -386,8 +389,10 @@ bool ns_capable(struct user_namespace *ns, int cap)
>  
>  	if (security_capable(current_cred(), ns, cap) == 0) {
>  		current->flags |= PF_SUPERPRIV;
> +		trace_capable(current->pid, cap, true);
>  		return true;
>  	}
> +	trace_capable(current->pid, cap, false);
>  	return false;
>  }
>  EXPORT_SYMBOL(ns_capable);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-19  6:59 ` Eric W. Biederman
@ 2012-05-19 18:39   ` Kok, Auke-jan H
  2012-05-22  0:03     ` Eric W. Biederman
  0 siblings, 1 reply; 12+ messages in thread
From: Kok, Auke-jan H @ 2012-05-19 18:39 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

On Fri, May 18, 2012 at 11:59 PM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> Auke Kok <auke-jan.h.kok@intel.com> writes:
>
> > Add a simple trace event for capable().
> >
> > There's been a lot of discussion around capable(), and there
> > are plenty of tools to help reduce capabilities' usage from
> > userspace. A major gap however is that it's almost impossible
> > to see or verify which bits are requested from either userspace
> > or in the kernel.
> >
> > This patch adds a minimal tracer that will print out which
> > CAPs are requested and whether the request was granted.
>
> A small comment assigned from the other issues.
>
> current->pid for anything going to userspace is broken,
> and in fact current->pid should be killed on of these days.
>
> Which pid namespace is your tracer running in?

init - I currently have no need for namespaces myself at all, and, as I replied
to Serge and Eric already - I'll see if I can fis up the tracer with their
suggestions.

Auke

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-18 23:19     ` Serge Hallyn
@ 2012-05-20 13:10       ` Serge E. Hallyn
  0 siblings, 0 replies; 12+ messages in thread
From: Serge E. Hallyn @ 2012-05-20 13:10 UTC (permalink / raw)
  To: Serge Hallyn
  Cc: Kok, Auke-jan H, richard -rw- weinberger, Serge Hallyn,
	linux-security-module, linux-kernel, Eric Paris

Quoting Serge Hallyn (serge@hallyn.com):
> 
> ----- Original message -----
> > On Fri, May 18, 2012 at 3:33 PM, richard -rw- weinberger
> > <richard.weinberger@gmail.com> wrote:
> > > 
> > > On Thu, May 17, 2012 at 9:50 PM, Auke Kok <auke-jan.h.kok@intel.com>
> > > wrote:
> > > > Add a simple trace event for capable().
> > > > 
> > > > There's been a lot of discussion around capable(), and there
> > > > are plenty of tools to help reduce capabilities' usage from
> > > > userspace. A major gap however is that it's almost impossible
> > > > to see or verify which bits are requested from either userspace
> > > > or in the kernel.
> > > > 
> > > > This patch adds a minimal tracer that will print out which
> > > > CAPs are requested and whether the request was granted.
> > > 
> > > Can we please have support for user namespaces?
> > > At least idicate whether the current namespace is init_user_ns or not.
> > 
> > that was the main reason for sending this out already - that should be
> > trivial to add to the trace event, but I haven't looked at namespaces
> > yet myself. I'll check it out.
> > 
> 
> right, trivial to add, but either go through linux-next or wait for Eric's
> patchset to move from there to Linus' tree.  Print the
> from_kuid(&init_user_ns, current_uid()), and if not in init_user_ns then also
> print the ns creator and task uid in his own ns.
> 
> I don't think you need to do that right now.

Oh, you'll also need to add the uid (in init_user_ns) of the owner of
the target namespace ('ns').  Otherwise, the admin may freak out seeing
uid 500 got cap_sys_admin :)

-serge

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-19 18:39   ` Kok, Auke-jan H
@ 2012-05-22  0:03     ` Eric W. Biederman
  2012-05-22  2:17       ` Kok, Auke-jan H
  0 siblings, 1 reply; 12+ messages in thread
From: Eric W. Biederman @ 2012-05-22  0:03 UTC (permalink / raw)
  To: Kok, Auke-jan H
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

"Kok, Auke-jan H" <auke-jan.h.kok@intel.com> writes:

> On Fri, May 18, 2012 at 11:59 PM, Eric W. Biederman
> <ebiederm@xmission.com> wrote:
>> Auke Kok <auke-jan.h.kok@intel.com> writes:
>>
>> > Add a simple trace event for capable().
>> >
>> > There's been a lot of discussion around capable(), and there
>> > are plenty of tools to help reduce capabilities' usage from
>> > userspace. A major gap however is that it's almost impossible
>> > to see or verify which bits are requested from either userspace
>> > or in the kernel.
>> >
>> > This patch adds a minimal tracer that will print out which
>> > CAPs are requested and whether the request was granted.
>>
>> A small comment assigned from the other issues.
>>
>> current->pid for anything going to userspace is broken,
>> and in fact current->pid should be killed on of these days.
>>
>> Which pid namespace is your tracer running in?
>
> init - I currently have no need for namespaces myself at all, and, as I replied
> to Serge and Eric already - I'll see if I can fis up the tracer with their
> suggestions.

Thanks.

A quick read of perf_event_open shows that the syscall is allowed by
unprivileged users in any context if sysctl_perf_event_paranoid is
set properly.  So it looks like the perf code needs to handle namespaces
properly if we are going to be reporting namespaced values like uid
and pids.  Even if no one cares today what about next week?

Eric

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-22  0:03     ` Eric W. Biederman
@ 2012-05-22  2:17       ` Kok, Auke-jan H
  2012-05-22 14:50         ` Eric W. Biederman
  0 siblings, 1 reply; 12+ messages in thread
From: Kok, Auke-jan H @ 2012-05-22  2:17 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

On Tue, May 22, 2012 at 12:03 AM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> "Kok, Auke-jan H" <auke-jan.h.kok@intel.com> writes:
>
>> On Fri, May 18, 2012 at 11:59 PM, Eric W. Biederman
>> <ebiederm@xmission.com> wrote:
>>> Auke Kok <auke-jan.h.kok@intel.com> writes:
>>>
>>> > Add a simple trace event for capable().
>>> >
>>> > There's been a lot of discussion around capable(), and there
>>> > are plenty of tools to help reduce capabilities' usage from
>>> > userspace. A major gap however is that it's almost impossible
>>> > to see or verify which bits are requested from either userspace
>>> > or in the kernel.
>>> >
>>> > This patch adds a minimal tracer that will print out which
>>> > CAPs are requested and whether the request was granted.
>>>
>>> A small comment assigned from the other issues.
>>>
>>> current->pid for anything going to userspace is broken,
>>> and in fact current->pid should be killed on of these days.
>>>
>>> Which pid namespace is your tracer running in?
>>
>> init - I currently have no need for namespaces myself at all, and, as I replied
>> to Serge and Eric already - I'll see if I can fis up the tracer with their
>> suggestions.
>
> Thanks.
>
> A quick read of perf_event_open shows that the syscall is allowed by
> unprivileged users in any context if sysctl_perf_event_paranoid is
> set properly.  So it looks like the perf code needs to handle namespaces
> properly if we are going to be reporting namespaced values like uid
> and pids.  Even if no one cares today what about next week?

I thought about dropping current->pid from this patch entirely and referring
to the comm+pid combination that is already printed in the event log.

That avoids the issue entirely on one side, and defers the problem with
namespaces entirely to the perf code, where it should probably be solved
in a consistend way anyway.

Would that be an appropriate solution, or do you think it's preferable to
fix the trace event to properly annotate namespaces? I'm slanting towards
just dropping current->pid from this patch for now.

Auke

>
> Eric

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Trace event for capable().
  2012-05-22  2:17       ` Kok, Auke-jan H
@ 2012-05-22 14:50         ` Eric W. Biederman
  0 siblings, 0 replies; 12+ messages in thread
From: Eric W. Biederman @ 2012-05-22 14:50 UTC (permalink / raw)
  To: Kok, Auke-jan H
  Cc: Serge Hallyn, linux-security-module, linux-kernel, Eric Paris

"Kok, Auke-jan H" <auke-jan.h.kok@intel.com> writes:

> On Tue, May 22, 2012 at 12:03 AM, Eric W. Biederman
> <ebiederm@xmission.com> wrote:
>> "Kok, Auke-jan H" <auke-jan.h.kok@intel.com> writes:
>>
>>> On Fri, May 18, 2012 at 11:59 PM, Eric W. Biederman
>>> <ebiederm@xmission.com> wrote:
>>>> Auke Kok <auke-jan.h.kok@intel.com> writes:
>>>>
>>>> > Add a simple trace event for capable().
>>>> >
>>>> > There's been a lot of discussion around capable(), and there
>>>> > are plenty of tools to help reduce capabilities' usage from
>>>> > userspace. A major gap however is that it's almost impossible
>>>> > to see or verify which bits are requested from either userspace
>>>> > or in the kernel.
>>>> >
>>>> > This patch adds a minimal tracer that will print out which
>>>> > CAPs are requested and whether the request was granted.
>>>>
>>>> A small comment assigned from the other issues.
>>>>
>>>> current->pid for anything going to userspace is broken,
>>>> and in fact current->pid should be killed on of these days.
>>>>
>>>> Which pid namespace is your tracer running in?
>>>
>>> init - I currently have no need for namespaces myself at all, and, as I replied
>>> to Serge and Eric already - I'll see if I can fis up the tracer with their
>>> suggestions.
>>
>> Thanks.
>>
>> A quick read of perf_event_open shows that the syscall is allowed by
>> unprivileged users in any context if sysctl_perf_event_paranoid is
>> set properly.  So it looks like the perf code needs to handle namespaces
>> properly if we are going to be reporting namespaced values like uid
>> and pids.  Even if no one cares today what about next week?
>
> I thought about dropping current->pid from this patch entirely and referring
> to the comm+pid combination that is already printed in the event log.
>
> That avoids the issue entirely on one side, and defers the problem with
> namespaces entirely to the perf code, where it should probably be solved
> in a consistend way anyway.

Yes.  There is at least one other place where we need to solve this.

> Would that be an appropriate solution, or do you think it's preferable to
> fix the trace event to properly annotate namespaces? I'm slanting towards
> just dropping current->pid from this patch for now.

I'm not quite certain in the context of perf.  Both because it is high
speed and because I don't understand perf very well.

The usual idiom is to hold a struct pid * in the data structure and then
to translate when the value is read out to userspace.  If we know who
the userspace reader is going to be at the time we log the message we
can translate when we log the information.

High speed probably conflicts with reference counts.

Eric

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-05-22 14:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-17 19:50 [PATCH] Trace event for capable() Auke Kok
2012-05-18 22:25 ` Serge Hallyn
2012-05-18 23:11   ` Kok, Auke-jan H
2012-05-18 22:33 ` richard -rw- weinberger
2012-05-18 23:09   ` Kok, Auke-jan H
2012-05-18 23:19     ` Serge Hallyn
2012-05-20 13:10       ` Serge E. Hallyn
2012-05-19  6:59 ` Eric W. Biederman
2012-05-19 18:39   ` Kok, Auke-jan H
2012-05-22  0:03     ` Eric W. Biederman
2012-05-22  2:17       ` Kok, Auke-jan H
2012-05-22 14:50         ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).