Skip to content

Commit e9bbfb4

Browse files
viktormalikmaddy-kerneldev
authored andcommitted
powerpc, perf: Check that current->mm is alive before getting user callchain
It may happen that mm is already released, which leads to kernel panic. This adds the NULL check for current->mm, similarly to commit 20afc60 ("x86, perf: Check that current->mm is alive before getting user callchain"). I was getting this panic when running a profiling BPF program (profile.py from bcc-tools): [26215.051935] Kernel attempted to read user page (588) - exploit attempt? (uid: 0) [26215.051950] BUG: Kernel NULL pointer dereference on read at 0x00000588 [26215.051952] Faulting instruction address: 0xc00000000020fac0 [26215.051957] Oops: Kernel access of bad area, sig: 11 [#1] [...] [26215.052049] Call Trace: [26215.052050] [c000000061da6d30] [c00000000020fc10] perf_callchain_user_64+0x2d0/0x490 (unreliable) [26215.052054] [c000000061da6dc0] [c00000000020f92c] perf_callchain_user+0x1c/0x30 [26215.052057] [c000000061da6de0] [c0000000005ab2a0] get_perf_callchain+0x100/0x360 [26215.052063] [c000000061da6e70] [c000000000573bc8] bpf_get_stackid+0x88/0xf0 [26215.052067] [c000000061da6ea0] [c008000000042258] bpf_prog_16d4ab9ab662f669_do_perf_event+0xf8/0x274 [...] In addition, move storing the top-level stack entry to generic perf_callchain_user to make sure the top-evel entry is always captured, even if current->mm is NULL. Fixes: 20002de ("perf_counter: powerpc: Add callchain support") Signed-off-by: Viktor Malik <[email protected]> Tested-by: Qiao Zhao <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Reviewed-by: Saket Kumar Bhaskar <[email protected]> [Maddy: fixed message to avoid checkpatch format style error] Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 0a8321d commit e9bbfb4

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

arch/powerpc/perf/callchain.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
103103
void
104104
perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs)
105105
{
106+
perf_callchain_store(entry, perf_arch_instruction_pointer(regs));
107+
108+
if (!current->mm)
109+
return;
110+
106111
if (!is_32bit_task())
107112
perf_callchain_user_64(entry, regs);
108113
else

arch/powerpc/perf/callchain_32.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
142142
next_ip = perf_arch_instruction_pointer(regs);
143143
lr = regs->link;
144144
sp = regs->gpr[1];
145-
perf_callchain_store(entry, next_ip);
146145

147146
while (entry->nr < entry->max_stack) {
148147
fp = (unsigned int __user *) (unsigned long) sp;

arch/powerpc/perf/callchain_64.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
7777
next_ip = perf_arch_instruction_pointer(regs);
7878
lr = regs->link;
7979
sp = regs->gpr[1];
80-
perf_callchain_store(entry, next_ip);
8180

8281
while (entry->nr < entry->max_stack) {
8382
fp = (unsigned long __user *) sp;

0 commit comments

Comments
 (0)