From patchwork Thu Aug 23 06:30:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Neuling X-Patchwork-Id: 179514 X-Patchwork-Delegate: benh@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 506B52C0331 for ; Thu, 23 Aug 2012 16:31:14 +1000 (EST) Received: by ozlabs.org (Postfix) id 04DF42C0094; Thu, 23 Aug 2012 16:30:44 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from localhost.localdomain (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id DFD8C2C0090; Thu, 23 Aug 2012 16:30:43 +1000 (EST) Received: by localhost.localdomain (Postfix, from userid 1000) id 27B61D4742F; Thu, 23 Aug 2012 16:30:43 +1000 (EST) Received: from neuling.org (localhost [127.0.0.1]) by localhost.localdomain (Postfix) with ESMTP id 23961D4186F; Thu, 23 Aug 2012 16:30:43 +1000 (EST) From: Michael Neuling To: benh@kernel.crashing.org, linuxppc-dev@ozlabs.org Subject: [PATCH] powerpc: Fix null pointer deref in perf hardware breakpoints In-reply-to: <1345620143-17289-3-git-send-email-mikey@neuling.org> References: <1345620143-17289-1-git-send-email-mikey@neuling.org> <1345620143-17289-3-git-send-email-mikey@neuling.org> Comments: In-reply-to Michael Neuling message dated "Wed, 22 Aug 2012 17:22:23 +1000." X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.3.1 Date: Thu, 23 Aug 2012 16:30:43 +1000 Message-ID: <8695.1345703443@neuling.org> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Currently if you are doing a global perf recording with hardware breakpoints (ie perf record -e mem:0xdeadbeef -a), you can oops with: Faulting instruction address: 0xc000000000738890 cpu 0xc: Vector: 300 (Data Access) at [c0000003f76af8d0] pc: c000000000738890: .hw_breakpoint_handler+0xa0/0x1e0 lr: c000000000738830: .hw_breakpoint_handler+0x40/0x1e0 sp: c0000003f76afb50 msr: 8000000000001032 dar: 6f0 dsisr: 42000000 current = 0xc0000003f765ac00 paca = 0xc00000000f262a00 softe: 0 irq_happened: 0x01 pid = 6810, comm = loop-read enter ? for help [c0000003f76afbe0] c00000000073cd04 .notifier_call_chain.isra.0+0x84/0xe0 [c0000003f76afc80] c00000000073cdbc .notify_die+0x3c/0x60 [c0000003f76afd20] c0000000000139f0 .do_dabr+0x40/0xf0 [c0000003f76afe30] c000000000005a9c handle_dabr_fault+0x14/0x48 --- Exception: 300 (Data Access) at 0000000010000480 SP (ff8679e0) is in userspace This is because we don't check to see if the break point is associated with task before we deference the task_struct pointer. This changes the update to use current. Signed-off-by: Michael Neuling --- v2: mpe pointed out that we should be using current here so that once we single step the next instruction, we know where to store the perf event. Confirming this, the original patch didn't actually record any data when we used -a even when we hit. This new patch fixes this so that -a doesn't oops and records data too! diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c index f3a82dd..956a4c4 100644 --- a/arch/powerpc/kernel/hw_breakpoint.c +++ b/arch/powerpc/kernel/hw_breakpoint.c @@ -253,7 +253,7 @@ int __kprobes hw_breakpoint_handler(struct die_args *args) /* Do not emulate user-space instructions, instead single-step them */ if (user_mode(regs)) { - bp->ctx->task->thread.last_hit_ubp = bp; + current->thread.last_hit_ubp = bp; regs->msr |= MSR_SE; goto out; }