Skip to content

Commit bb19af8

Browse files
Madhavan Srinivasanmpe
Madhavan Srinivasan
authored andcommitted
powerpc/perf: Prevent kernel address leak to userspace via BHRB buffer
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 <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent e1ebd0e commit bb19af8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arch/powerpc/perf/core-book3s.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
457457
/* invalid entry */
458458
continue;
459459

460+
/*
461+
* BHRB rolling buffer could very much contain the kernel
462+
* addresses at this point. Check the privileges before
463+
* exporting it to userspace (avoid exposure of regions
464+
* where we could have speculative execution)
465+
*/
466+
if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN) &&
467+
is_kernel_addr(addr))
468+
continue;
469+
460470
/* Branches are read most recent first (ie. mfbhrb 0 is
461471
* the most recent branch).
462472
* There are two types of valid entries:

0 commit comments

Comments
 (0)