Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1214638 > unrolled thread

[PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems

Started byAlexander Shishkin <alexander.shishkin@linux.intel.com>
First post2015-08-27 17:20 +0200
Last post2015-08-28 11:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-08-27 17:20 +0200
    Re: [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged  users on paranoid systems Ingo Molnar <mingo@kernel.org> - 2015-08-28 07:40 +0200
      Re: [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2015-08-28 11:50 +0200

#1214638 — [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2015-08-27 17:20 +0200
Subject[PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems
Message-ID<q2785-8ds-9@gated-at.bofh.it>
BTS leaks kernel addresses even in userspace-only mode due to imprecise IP
sampling, so sometimes syscall entry points or page fault handler addresses
end up in a userspace trace.

Now, intel_bts driver exports trace data zero-copy, it does not scan through
it to filter out the kernel addresses and it's would be a O(n) job.

To work around this situation, this patch forbids the use of intel_bts
driver by unprivileged users with paranoid setting higher than 1, which
forbids kernel tracing.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 arch/x86/kernel/cpu/perf_event_intel_bts.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_bts.c b/arch/x86/kernel/cpu/perf_event_intel_bts.c
index 80df16e020..4f6daff92d 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_bts.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_bts.c
@@ -495,6 +495,16 @@ static int bts_event_init(struct perf_event *event)
 	if (x86_add_exclusive(x86_lbr_exclusive_bts))
 		return -EBUSY;
 
+	/*
+	 * BTS leaks kernel addresses even when CPL0 tracing is
+	 * disabled, so disallow intel_bts driver for unprivileged
+	 * users on paranoid systems since it provides trace data
+	 * to the user in a zero-copy fashion.
+	 */
+	if (event->attr.exclude_kernel && perf_paranoid_kernel() &&
+	    !capable(CAP_SYS_ADMIN))
+		return -EACCES;
+
 	ret = x86_reserve_hardware();
 	if (ret) {
 		x86_del_exclusive(x86_lbr_exclusive_bts);
-- 
2.5.0

--
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/

[toc] | [next] | [standalone]


#1215102 — Re: [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems

FromIngo Molnar <mingo@kernel.org>
Date2015-08-28 07:40 +0200
SubjectRe: [PATCH 2/2] perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems
Message-ID<q2kym-2kM-11@gated-at.bofh.it>
In reply to#1214638
* Alexander Shishkin <alexander.shishkin@linux.intel.com> wrote:

> BTS leaks kernel addresses even in userspace-only mode due to imprecise IP
> sampling, so sometimes syscall entry points or page fault handler addresses
> end up in a userspace trace.
> 
> Now, intel_bts driver exports trace data zero-copy, it does not scan through
> it to filter out the kernel addresses and it's would be a O(n) job.
> 
> To work around this situation, this patch forbids the use of intel_bts
> driver by unprivileged users with paranoid setting higher than 1, which
> forbids kernel tracing.
> 
> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> ---
>  arch/x86/kernel/cpu/perf_event_intel_bts.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/perf_event_intel_bts.c b/arch/x86/kernel/cpu/perf_event_intel_bts.c
> index 80df16e020..4f6daff92d 100644
> --- a/arch/x86/kernel/cpu/perf_event_intel_bts.c
> +++ b/arch/x86/kernel/cpu/perf_event_intel_bts.c
> @@ -495,6 +495,16 @@ static int bts_event_init(struct perf_event *event)
>  	if (x86_add_exclusive(x86_lbr_exclusive_bts))
>  		return -EBUSY;
>  
> +	/*
> +	 * BTS leaks kernel addresses even when CPL0 tracing is
> +	 * disabled, so disallow intel_bts driver for unprivileged
> +	 * users on paranoid systems since it provides trace data
> +	 * to the user in a zero-copy fashion.
> +	 */
> +	if (event->attr.exclude_kernel && perf_paranoid_kernel() &&
> +	    !capable(CAP_SYS_ADMIN))
> +		return -EACCES;

I.e. it's disabled by default as well, with default paranoia settings?

Thanks,

	Ingo
--
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/

[toc] | [prev] | [next] | [standalone]


#1215245

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2015-08-28 11:50 +0200
Message-ID<q2osi-7VN-15@gated-at.bofh.it>
In reply to#1215102
Ingo Molnar <mingo@kernel.org> writes:

> * Alexander Shishkin <alexander.shishkin@linux.intel.com> wrote:
>
>> BTS leaks kernel addresses even in userspace-only mode due to imprecise IP
>> sampling, so sometimes syscall entry points or page fault handler addresses
>> end up in a userspace trace.
>> 
>> Now, intel_bts driver exports trace data zero-copy, it does not scan through
>> it to filter out the kernel addresses and it's would be a O(n) job.
>> 
>> To work around this situation, this patch forbids the use of intel_bts
>> driver by unprivileged users with paranoid setting higher than 1, which
>> forbids kernel tracing.
>> 
>> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> ---
>>  arch/x86/kernel/cpu/perf_event_intel_bts.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>> 
>> diff --git a/arch/x86/kernel/cpu/perf_event_intel_bts.c b/arch/x86/kernel/cpu/perf_event_intel_bts.c
>> index 80df16e020..4f6daff92d 100644
>> --- a/arch/x86/kernel/cpu/perf_event_intel_bts.c
>> +++ b/arch/x86/kernel/cpu/perf_event_intel_bts.c
>> @@ -495,6 +495,16 @@ static int bts_event_init(struct perf_event *event)
>>  	if (x86_add_exclusive(x86_lbr_exclusive_bts))
>>  		return -EBUSY;
>>  
>> +	/*
>> +	 * BTS leaks kernel addresses even when CPL0 tracing is
>> +	 * disabled, so disallow intel_bts driver for unprivileged
>> +	 * users on paranoid systems since it provides trace data
>> +	 * to the user in a zero-copy fashion.
>> +	 */
>> +	if (event->attr.exclude_kernel && perf_paranoid_kernel() &&
>> +	    !capable(CAP_SYS_ADMIN))
>> +		return -EACCES;
>
> I.e. it's disabled by default as well, with default paranoia settings?

Actually no, the kernel's default is 1, which allows kernel profiling
for unprivileged users. Distros might be more strict though.

Regards,
--
Alex
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web