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=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 C9A49C43381 for ; Fri, 1 Mar 2019 13:46:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D3CC20838 for ; Fri, 1 Mar 2019 13:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732259AbfCANqz (ORCPT ); Fri, 1 Mar 2019 08:46:55 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:35238 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387620AbfCANqy (ORCPT ); Fri, 1 Mar 2019 08:46:54 -0500 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 76F1CA78; Fri, 1 Mar 2019 05:46:54 -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 8AE5B3F5C1; Fri, 1 Mar 2019 05:46:53 -0800 (PST) Date: Fri, 1 Mar 2019 13:46:51 +0000 From: Mark Rutland To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, stable@vger.kernel.org Subject: Re: [PATCH 02/10] arm64: debug: Ensure debug handlers check triggering exception level Message-ID: <20190301134650.GC15517@lakrids.cambridge.arm.com> References: <20190301132809.24653-1-will.deacon@arm.com> <20190301132809.24653-3-will.deacon@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190301132809.24653-3-will.deacon@arm.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Fri, Mar 01, 2019 at 01:28:01PM +0000, Will Deacon wrote: > Debug exception handlers may be called for exceptions generated both by > user and kernel code. In many cases, this is checked explicitly, but > in other cases things either happen to work by happy accident or they > go slightly wrong. For example, executing 'brk #4' from userspace will > enter the kprobes code and be ignored, but the instruction will be > retried forever in userspace instead of delivering a SIGTRAP. > > Fix this issue in the most stable-friendly fashion by simply adding > explicit checks of the triggering exception level to all of our debug > exception handlers. > > Cc: > Signed-off-by: Will Deacon It might be worth noting in the commit message that this also makes the functions consistentluy use the DBG_HOOK_* mnemonics, but either way: Reviewed-by: Mark Rutland Mark. > --- > arch/arm64/kernel/kgdb.c | 14 ++++++++++---- > arch/arm64/kernel/probes/kprobes.c | 6 ++++++ > 2 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c > index ce46c4cdf368..691854b77c7f 100644 > --- a/arch/arm64/kernel/kgdb.c > +++ b/arch/arm64/kernel/kgdb.c > @@ -244,27 +244,33 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, > > static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr) > { > + if (user_mode(regs)) > + return DBG_HOOK_ERROR; > + > kgdb_handle_exception(1, SIGTRAP, 0, regs); > - return 0; > + return DBG_HOOK_HANDLED; > } > NOKPROBE_SYMBOL(kgdb_brk_fn) > > static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) > { > + if (user_mode(regs)) > + return DBG_HOOK_ERROR; > + > compiled_break = 1; > kgdb_handle_exception(1, SIGTRAP, 0, regs); > > - return 0; > + return DBG_HOOK_HANDLED; > } > NOKPROBE_SYMBOL(kgdb_compiled_brk_fn); > > static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) > { > - if (!kgdb_single_step) > + if (user_mode(regs) || !kgdb_single_step) > return DBG_HOOK_ERROR; > > kgdb_handle_exception(1, SIGTRAP, 0, regs); > - return 0; > + return DBG_HOOK_HANDLED; > } > NOKPROBE_SYMBOL(kgdb_step_brk_fn); > > diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c > index f17afb99890c..7fb6f3aa5ceb 100644 > --- a/arch/arm64/kernel/probes/kprobes.c > +++ b/arch/arm64/kernel/probes/kprobes.c > @@ -450,6 +450,9 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) > struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); > int retval; > > + if (user_mode(regs)) > + return DBG_HOOK_ERROR; > + > /* return error if this is not our step */ > retval = kprobe_ss_hit(kcb, instruction_pointer(regs)); > > @@ -466,6 +469,9 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) > int __kprobes > kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) > { > + if (user_mode(regs)) > + return DBG_HOOK_ERROR; > + > kprobe_handler(regs); > return DBG_HOOK_HANDLED; > } > -- > 2.11.0 >