Re: [PATCH] Trace event for capable().

From: Eric W. Biederman
Date: Tue May 22 2012 - 10:50:19 EST


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

> On Tue, May 22, 2012 at 12:03 AM, Eric W. Biederman
> <ebiederm@xxxxxxxxxxxx> wrote:
>> "Kok, Auke-jan H" <auke-jan.h.kok@xxxxxxxxx> writes:
>>
>>> On Fri, May 18, 2012 at 11:59 PM, Eric W. Biederman
>>> <ebiederm@xxxxxxxxxxxx> wrote:
>>>> Auke Kok <auke-jan.h.kok@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/