Skip to content

Commit f41d84d

Browse files
Ravi Bangoriampe
authored andcommitted
powerpc/perf: Dereference BHRB entries safely
It's theoretically possible that branch instructions recorded in BHRB (Branch History Rolling Buffer) entries have already been unmapped before they are processed by the kernel. Hence, trying to dereference such memory location will result in a crash. eg: Unable to handle kernel paging request for data at address 0xd000000019c41764 Faulting instruction address: 0xc000000000084a14 NIP [c000000000084a14] branch_target+0x4/0x70 LR [c0000000000eb828] record_and_restart+0x568/0x5c0 Call Trace: [c0000000000eb3b4] record_and_restart+0xf4/0x5c0 (unreliable) [c0000000000ec378] perf_event_interrupt+0x298/0x460 [c000000000027964] performance_monitor_exception+0x54/0x70 [c000000000009ba4] performance_monitor_common+0x114/0x120 Fix it by deferefencing the addresses safely. Fixes: 6912318 ("powerpc/perf: Fix setting of "to" addresses for BHRB") Cc: [email protected] # v3.10+ Suggested-by: Naveen N. Rao <[email protected]> Signed-off-by: Ravi Bangoria <[email protected]> Reviewed-by: Naveen N. Rao <[email protected]> [mpe: Use probe_kernel_read() which is clearer, tweak change log] Signed-off-by: Michael Ellerman <[email protected]>
1 parent d810418 commit f41d84d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/powerpc/perf/core-book3s.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,12 @@ static __u64 power_pmu_bhrb_to(u64 addr)
410410
int ret;
411411
__u64 target;
412412

413-
if (is_kernel_addr(addr))
414-
return branch_target((unsigned int *)addr);
413+
if (is_kernel_addr(addr)) {
414+
if (probe_kernel_read(&instr, (void *)addr, sizeof(instr)))
415+
return 0;
416+
417+
return branch_target(&instr);
418+
}
415419

416420
/* Userspace: need copy instruction here then translate it */
417421
pagefault_disable();

0 commit comments

Comments
 (0)