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=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 > 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=unavailable 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 1348DC43381 for ; Fri, 1 Mar 2019 13:46:59 +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 D56F220838 for ; Fri, 1 Mar 2019 13:46:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LzMeenKj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D56F220838 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=3dRQOtbWJRy0ATjUU5bvN0f/iAWGBB2e4HfMvqwmPDE=; b=LzMeenKjjXyaCz 3/MKiZSQAKIiFuMhoN65HkjqDRLNCyu/RgUKdBzzuGqYt+5x1+JSYenRlJIYs8ms97ceotYw48HNP yOBFp5+fQMttCd4f/Hqs+oA1bpRZOXG25CxguAfAVnHMZhNVAzpvjToPEE10CVTcLUn6AcJn9Az1F 6+rsGMzxjv5ziVhoWU+9qAzypTbZ3wwISmO4JteKSbMs0roDaiSuXKfDrgb0rCkVCq4XATNKo5ZID D+kdzaSiwr8lwar93jC1PEDtQyAbuyFtyhspQF16AK2kXS4k3Bu1zB5B6KlOBv7kuFIPqKHEATVum 34vLig5NcuOrH5Z5229Q==; 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 1gziV7-0000Jq-Vp; Fri, 01 Mar 2019 13:46:57 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gziV4-0000JR-T6 for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2019 13:46:56 +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 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 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-Disposition: inline In-Reply-To: <20190301132809.24653-3-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_054654_953123_CA9E6478 X-CRM114-Status: GOOD ( 19.48 ) 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, stable@vger.kernel.org, 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: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 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel