public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: fix hypervisor branch sampling permission check
@ 2013-06-06  9:02 Stephane Eranian
  2013-06-06  9:12 ` Petr Matousek
  2013-06-19 18:38 ` [tip:perf/core] perf: Fix " tip-bot for Stephane Eranian
  0 siblings, 2 replies; 3+ messages in thread
From: Stephane Eranian @ 2013-06-06  9:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, mingo, pmatouse, meissner, security, oss-security, ak


Commit 2b923c8 perf/x86: Check branch sampling priv level in generic code
was missing the check for the hypervisor (HV) priv level, so add it back.

With this patch, we get the following correct behavior:

  # echo 2 >/proc/sys/kernel/perf_event_paranoid 

  $ perf record -j any,k noploop 1
  Error:
  You may not have permission to collect stats.
  Consider tweaking /proc/sys/kernel/perf_event_paranoid:
   -1 - Not paranoid at all
    0 - Disallow raw tracepoint access for unpriv
    1 - Disallow cpu events for unpriv
    2 - Disallow kernel profiling for unpriv

   $ perf record -j any,hv noploop 1
   Error:
   You may not have permission to collect stats.
   Consider tweaking /proc/sys/kernel/perf_event_paranoid:
    -1 - Not paranoid at all
     0 - Disallow raw tracepoint access for unpriv
     1 - Disallow cpu events for unpriv
     2 - Disallow kernel profiling for unpriv

Signed-off-by: Stephane Eranian <eranian@google.com>
---
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 95edd5a..f0880fb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6501,8 +6501,8 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
 			 */
 			attr->branch_sample_type = mask;
 		}
-		/* kernel level capture: check permissions */
-		if ((mask & PERF_SAMPLE_BRANCH_KERNEL)
+		/* privileged levels capture (kernel, hv): check permissions */
+		if ((mask & PERF_SAMPLE_BRANCH_PERM_PLM)
 		    && perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
 			return -EACCES;
 	}

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

* Re: [PATCH] perf: fix hypervisor branch sampling permission check
  2013-06-06  9:02 [PATCH] perf: fix hypervisor branch sampling permission check Stephane Eranian
@ 2013-06-06  9:12 ` Petr Matousek
  2013-06-19 18:38 ` [tip:perf/core] perf: Fix " tip-bot for Stephane Eranian
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Matousek @ 2013-06-06  9:12 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: linux-kernel, peterz, mingo, meissner, security, oss-security, ak

On Thu, Jun 06, 2013 at 11:02:04AM +0200, Stephane Eranian wrote:
> 
> Commit 2b923c8 perf/x86: Check branch sampling priv level in generic code
> was missing the check for the hypervisor (HV) priv level, so add it back.
> 
> With this patch, we get the following correct behavior:
> 
>   # echo 2 >/proc/sys/kernel/perf_event_paranoid 
> 
>   $ perf record -j any,k noploop 1
>   Error:
>   You may not have permission to collect stats.
>   Consider tweaking /proc/sys/kernel/perf_event_paranoid:
>    -1 - Not paranoid at all
>     0 - Disallow raw tracepoint access for unpriv
>     1 - Disallow cpu events for unpriv
>     2 - Disallow kernel profiling for unpriv
> 
>    $ perf record -j any,hv noploop 1
>    Error:
>    You may not have permission to collect stats.
>    Consider tweaking /proc/sys/kernel/perf_event_paranoid:
>     -1 - Not paranoid at all
>      0 - Disallow raw tracepoint access for unpriv
>      1 - Disallow cpu events for unpriv
>      2 - Disallow kernel profiling for unpriv
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>
> ---
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 95edd5a..f0880fb 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6501,8 +6501,8 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
>  			 */
>  			attr->branch_sample_type = mask;
>  		}
> -		/* kernel level capture: check permissions */
> -		if ((mask & PERF_SAMPLE_BRANCH_KERNEL)
> +		/* privileged levels capture (kernel, hv): check permissions */
> +		if ((mask & PERF_SAMPLE_BRANCH_PERM_PLM)
>  		    && perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
>  			return -EACCES;
>  	}

Acked-by: Petr Matousek <pmatouse@redhat.com>

-- 
Petr Matousek / Red Hat Security Response Team

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

* [tip:perf/core] perf: Fix hypervisor branch sampling permission check
  2013-06-06  9:02 [PATCH] perf: fix hypervisor branch sampling permission check Stephane Eranian
  2013-06-06  9:12 ` Petr Matousek
@ 2013-06-19 18:38 ` tip-bot for Stephane Eranian
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Stephane Eranian @ 2013-06-19 18:38 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, hpa, mingo, peterz, pmatouse, tglx

Commit-ID:  e712209a9e0b70e78b13847738eb66fe37412515
Gitweb:     http://git.kernel.org/tip/e712209a9e0b70e78b13847738eb66fe37412515
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 6 Jun 2013 11:02:04 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 19 Jun 2013 12:50:21 +0200

perf: Fix hypervisor branch sampling permission check

Commit 2b923c8 perf/x86: Check branch sampling priv level in generic code
was missing the check for the hypervisor (HV) priv level, so add it back.

With this patch, we get the following correct behavior:

  # echo 2 >/proc/sys/kernel/perf_event_paranoid

  $ perf record -j any,k noploop 1
  Error:
  You may not have permission to collect stats.
  Consider tweaking /proc/sys/kernel/perf_event_paranoid:
   -1 - Not paranoid at all
    0 - Disallow raw tracepoint access for unpriv
    1 - Disallow cpu events for unpriv
    2 - Disallow kernel profiling for unpriv

   $ perf record -j any,hv noploop 1
   Error:
   You may not have permission to collect stats.
   Consider tweaking /proc/sys/kernel/perf_event_paranoid:
    -1 - Not paranoid at all
     0 - Disallow raw tracepoint access for unpriv
     1 - Disallow cpu events for unpriv
     2 - Disallow kernel profiling for unpriv

Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Petr Matousek <pmatouse@redhat.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20130606090204.GA3725@quad
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d0e0d0d..aca95bc 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6573,8 +6573,8 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
 			 */
 			attr->branch_sample_type = mask;
 		}
-		/* kernel level capture: check permissions */
-		if ((mask & PERF_SAMPLE_BRANCH_KERNEL)
+		/* privileged levels capture (kernel, hv): check permissions */
+		if ((mask & PERF_SAMPLE_BRANCH_PERM_PLM)
 		    && perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
 			return -EACCES;
 	}

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

end of thread, other threads:[~2013-06-19 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06  9:02 [PATCH] perf: fix hypervisor branch sampling permission check Stephane Eranian
2013-06-06  9:12 ` Petr Matousek
2013-06-19 18:38 ` [tip:perf/core] perf: Fix " tip-bot for Stephane Eranian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox