summaryrefslogtreecommitdiff
path: root/arch/powerpc/perf
diff options
context:
space:
mode:
authorMadhavan Srinivasan <maddy@linux.vnet.ibm.com>2018-03-21 17:10:25 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-30 07:50:43 +0200
commit0ebbbeb8c4651c3566028df308d8b53b09105e3e (patch)
treeabae9e0937f8d38e6b9b9c2822cba3bdb4515fd3 /arch/powerpc/perf
parent2a48e89c37bf60872a297cf584544826a44c29b7 (diff)
downloadlinux-0ebbbeb8c4651c3566028df308d8b53b09105e3e.tar.gz
linux-0ebbbeb8c4651c3566028df308d8b53b09105e3e.tar.bz2
linux-0ebbbeb8c4651c3566028df308d8b53b09105e3e.zip
powerpc/perf: Prevent kernel address leak to userspace via BHRB buffer
[ Upstream commit bb19af816025d495376bd76bf6fbcf4244f9a06d ] The current Branch History Rolling Buffer (BHRB) code does not check for any privilege levels before updating the data from BHRB. This could leak kernel addresses to userspace even when profiling only with userspace privileges. Add proper checks to prevent it. Acked-by: Balbir Singh <bsingharora@gmail.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch/powerpc/perf')
-rw-r--r--arch/powerpc/perf/core-book3s.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index bf949623de90..bc48d4d77594 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -448,6 +448,16 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
/* invalid entry */
continue;
+ /*
+ * BHRB rolling buffer could very much contain the kernel
+ * addresses at this point. Check the privileges before
+ * exporting it to userspace (avoid exposure of regions
+ * where we could have speculative execution)
+ */
+ if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN) &&
+ is_kernel_addr(addr))
+ continue;
+
/* Branches are read most recent first (ie. mfbhrb 0 is
* the most recent branch).
* There are two types of valid entries: