From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ACAEC43381 for ; Fri, 1 Mar 2019 14:12:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 57D472084D for ; Fri, 1 Mar 2019 14:12:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pl5U6xEn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57D472084D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f3Olt1aR8go0rXITJ7JgV9P6yukTl05oG45o+CZKIxs=; b=pl5U6xEnwo+9Wh CbJPFKaPKHVN5OjyGfWgXcdTsyrHuA5I6vd5ECvRb2jqbnCrsnvBZshdeZVEPprODyb0pwp+5osdK UZP7QEYQHd6hY45mkhADGBUJ0wAA5zU3iZ2kP3R6aDCUVMYp70qgCepUXj3dm4q12D4in2gUjfY4E mDVgJjCGGzt0f2jY7+oe6j6Hb8o07RAs8blyvC/+mtvt2p5Sw9a2IYW8C821OCWaXF5T5E0HjsvqQ Et/Mou/bALYi2RNrsvIedJcgKKOqwOZvjHxx2FrWLlTNN6/zvPPXD7YUhy5AFVaZO6SrPAHFxUccX RIkgtecx1rSLAClSFuFw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gziu9-0003Pl-PQ; Fri, 01 Mar 2019 14:12:49 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gziu6-0003PP-3i for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2019 14:12:47 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ADBBBA78; Fri, 1 Mar 2019 06:12:45 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E436B3F720; Fri, 1 Mar 2019 06:12:44 -0800 (PST) Date: Fri, 1 Mar 2019 14:12:42 +0000 From: Mark Rutland To: Will Deacon Subject: Re: [PATCH 07/10] arm64: kprobes: Avoid calling kprobes debug handlers explicitly Message-ID: <20190301141242.GH15517@lakrids.cambridge.arm.com> References: <20190301132809.24653-1-will.deacon@arm.com> <20190301132809.24653-8-will.deacon@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190301132809.24653-8-will.deacon@arm.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190301_061246_171232_780CBA87 X-CRM114-Status: GOOD ( 19.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Mar 01, 2019 at 01:28:06PM +0000, Will Deacon wrote: > Kprobes bypasses our debug hook registration code so that it doesn't > get tangled up with recursive debug exceptions from things like lockdep: > > http://lists.infradead.org/pipermail/linux-arm-kernel/2015-February/324385.html > > However, since then, (a) the hook list has become RCU protected and (b) > the kprobes hooks were found not to filter out exceptions from userspace > correctly. On top of that, the step handler is invoked directly from > single_step_handler(), which *does* use the debug hook list, so it's > clearly not the end of the world. > > For now, have kprobes use the debug hook registration API like everybody > else. We can revisit this in the future if this is found to limit > coverage significantly. > > Signed-off-by: Will Deacon Reviewed-by: Mark Rutland Mark. > --- > arch/arm64/include/asm/kprobes.h | 2 -- > arch/arm64/kernel/debug-monitors.c | 10 ---------- > arch/arm64/kernel/probes/kprobes.c | 16 ++++++++++++++-- > 3 files changed, 14 insertions(+), 14 deletions(-) > > diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h > index d5a44cf859e9..21721fbf44e7 100644 > --- a/arch/arm64/include/asm/kprobes.h > +++ b/arch/arm64/include/asm/kprobes.h > @@ -54,8 +54,6 @@ void arch_remove_kprobe(struct kprobe *); > int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr); > int kprobe_exceptions_notify(struct notifier_block *self, > unsigned long val, void *data); > -int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr); > -int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr); > void kretprobe_trampoline(void); > void __kprobes *trampoline_probe_handler(struct pt_regs *regs); > > diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c > index 51946ecaf8e5..d9616c34a270 100644 > --- a/arch/arm64/kernel/debug-monitors.c > +++ b/arch/arm64/kernel/debug-monitors.c > @@ -258,10 +258,6 @@ static int single_step_handler(unsigned long unused, unsigned int esr, > if (!reinstall_suspended_bps(regs)) > return 0; > > -#ifdef CONFIG_KPROBES > - if (kprobe_single_step_handler(regs, esr) == DBG_HOOK_HANDLED) > - handler_found = true; > -#endif > if (!handler_found && call_step_hook(regs, esr) == DBG_HOOK_HANDLED) > handler_found = true; > > @@ -334,12 +330,6 @@ static int brk_handler(unsigned long unused, unsigned int esr, > { > bool handler_found = false; > > -#ifdef CONFIG_KPROBES > - if ((esr & BRK64_ESR_MASK) == BRK64_ESR_KPROBES) { > - if (kprobe_breakpoint_handler(regs, esr) == DBG_HOOK_HANDLED) > - handler_found = true; > - } > -#endif > if (!handler_found && call_break_hook(regs, esr) == DBG_HOOK_HANDLED) > handler_found = true; > > diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c > index 7fb6f3aa5ceb..3066ffd70cf5 100644 > --- a/arch/arm64/kernel/probes/kprobes.c > +++ b/arch/arm64/kernel/probes/kprobes.c > @@ -444,7 +444,7 @@ kprobe_ss_hit(struct kprobe_ctlblk *kcb, unsigned long addr) > return DBG_HOOK_ERROR; > } > > -int __kprobes > +static int __kprobes > kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) > { > struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); > @@ -466,7 +466,11 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) > return retval; > } > > -int __kprobes > +static struct step_hook kprobes_step_hook = { > + .fn = kprobe_single_step_handler, > +}; > + > +static int __kprobes > kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) > { > if (user_mode(regs)) > @@ -476,6 +480,11 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) > return DBG_HOOK_HANDLED; > } > > +static struct break_hook kprobes_break_hook = { > + .imm = BRK64_ESR_KPROBES, > + .fn = kprobe_breakpoint_handler, > +}; > + > bool arch_within_kprobe_blacklist(unsigned long addr) > { > if ((addr >= (unsigned long)__kprobes_text_start && > @@ -593,5 +602,8 @@ int __kprobes arch_trampoline_kprobe(struct kprobe *p) > > int __init arch_init_kprobes(void) > { > + register_kernel_break_hook(&kprobes_break_hook); > + register_kernel_step_hook(&kprobes_step_hook); > + > return 0; > } > -- > 2.11.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel