From patchwork Fri Mar 1 13:28:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 159477 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp734246jad; Fri, 1 Mar 2019 05:28:17 -0800 (PST) X-Google-Smtp-Source: APXvYqyvik1VHofuouNASWLSqxv+dROiDAfd1V32p6JdIrmSBnFnyFTs34xIozFxGwTVK32Ecc7n X-Received: by 2002:a63:c64c:: with SMTP id x12mr4862685pgg.285.1551446897915; Fri, 01 Mar 2019 05:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551446897; cv=none; d=google.com; s=arc-20160816; b=qrHKOwwjpc57EmUCREzmGZ5WnHZJj6mtorPmAZNcQozOof4gR8ARl0Wr0PsOXStty9 IIBvM4sZHa7m3Cvjnwa/MLm+c8sYi/aVZZ2OxR5Nqowg1AcPToHjZGKNZ9xynnGopJZR t8i0nWCoGeK9Hi+7X8IUV9+tO1+QWEP5MRUQ/LjYTR3c8lLVmMzFdwu6WPeTWpxQqGZB 4H2lkYyre1NK9knsrM+Vi7xWEELRK5B3DOyDNTMptv73f9n3JcAuq0+twEsaiKgC/UDU ujdD/2zWSoEn+Rid9/vwi4zR+hepfzxkJ827zn6IWBkNxWvdrrNmkGGrFnUXsW3GhXoJ ciQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=7WtimDScbDkuC77N2AIsblN8hDPeVK1DAteiwfWWk1A=; b=XHyh4dncEoYDjUisA+0dNy4ilqJ81LnssWAknDL00Syt2TqXCdfOdxROKGwc7Y7KlD g16GSBBtex5EZ+FqzGY9IVE5t8E/qoiYxF0s4Eht4HLXabaYL4mxIVegHq8xCqPmCqgL d/WyYul8rVP71aKeKO5saSqyXxUjWFtX5EQhbJypQu9Y3H5Qwr3+RmEt9FM4xE9WyrcP xb/pHrnoiyzyw7mdg/pnvADt0Zu0SpT0jBnzrXkNsVj47rjVwTpfpGvZzBf5kZcPz+uM 1p6T12yK6H9swR2iMU8DH7VhH62JD2rZ5mSYB+khvnjEED5u6p9tEubU2knb+cExbZ5V Qw7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cy1si22781169plb.429.2019.03.01.05.28.17; Fri, 01 Mar 2019 05:28:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728216AbfCAN2R (ORCPT + 14 others); Fri, 1 Mar 2019 08:28:17 -0500 Received: from foss.arm.com ([217.140.101.70]:34742 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727697AbfCAN2R (ORCPT ); Fri, 1 Mar 2019 08:28:17 -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 54D6B165C; Fri, 1 Mar 2019 05:28:16 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 44FF13F5C1; Fri, 1 Mar 2019 05:28:15 -0800 (PST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, mark.rutland@arm.com, Will Deacon , stable@vger.kernel.org Subject: [PATCH 01/10] arm64: debug: Don't propagate UNKNOWN FAR into si_code for debug signals Date: Fri, 1 Mar 2019 13:28:00 +0000 Message-Id: <20190301132809.24653-2-will.deacon@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190301132809.24653-1-will.deacon@arm.com> References: <20190301132809.24653-1-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org FAR_EL1 is UNKNOWN for all debug exceptions other than those caused by taking a hardware watchpoint. Unfortunately, if a debug handler returns a non-zero value, then we will propagate the UNKNOWN FAR value to userspace via the si_addr field of the SIGTRAP siginfo_t. Instead, let's set si_addr to take on the PC of the faulting instruction, which we have available in the current pt_regs. Cc: Signed-off-by: Will Deacon --- arch/arm64/mm/fault.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.11.0 Reviewed-by: Mark Rutland diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index efb7b2cbead5..ef46925096f0 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -824,11 +824,12 @@ void __init hook_debug_fault_code(int nr, debug_fault_info[nr].name = name; } -asmlinkage int __exception do_debug_exception(unsigned long addr, +asmlinkage int __exception do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr, struct pt_regs *regs) { const struct fault_info *inf = esr_to_debug_fault_info(esr); + unsigned long pc = instruction_pointer(regs); int rv; /* @@ -838,14 +839,14 @@ asmlinkage int __exception do_debug_exception(unsigned long addr, if (interrupts_enabled(regs)) trace_hardirqs_off(); - if (user_mode(regs) && !is_ttbr0_addr(instruction_pointer(regs))) + if (user_mode(regs) && !is_ttbr0_addr(pc)) arm64_apply_bp_hardening(); - if (!inf->fn(addr, esr, regs)) { + if (!inf->fn(addr_if_watchpoint, esr, regs)) { rv = 1; } else { arm64_notify_die(inf->name, regs, - inf->sig, inf->code, (void __user *)addr, esr); + inf->sig, inf->code, (void __user *)pc, esr); rv = 0; } From patchwork Fri Mar 1 13:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 159478 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp734263jad; Fri, 1 Mar 2019 05:28:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx5gdq1CXJtyF+0Y3fZLZrdq4oQi9WhPbQtgD2MuHPxe8WKQ1xBJCWUSK7W5uFcw0RqHV/l X-Received: by 2002:a63:cc05:: with SMTP id x5mr4798132pgf.31.1551446898735; Fri, 01 Mar 2019 05:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551446898; cv=none; d=google.com; s=arc-20160816; b=mVPOtIBEWpeM+LjDh2Y6LmoRQB12LCaluDIUnuqrIYrKw5gtWJL5GtW0MQ80oY/SSN U0do28+bfT1lHhwRCQq30s7ZfWTlPH31Xk/bWS1iEctyLqsTICzbDjy7DJQbiy/ilP3d O69u6goj2UdjWJcwUSWYjFSaeR7j3lBWcj5FBTWNMLbmdCAu66D8X3rBtTmJpUb1+fEK FqBhgYukyKL4hiN7uSA3BYr9kz8TgWmYkRdgg0WBT9rbRsxEY9sFkIDpEgIAlUYz7oSM e+QuHnD1ho5Hbi1OGlEBdaGwvVNN6WOQUkNsQ8L+zEYXNcZK59XvxbpOURT0om0D3q7T eNUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ld0eF/bwt22Oh6ysJeua2FImRA54RdArP7PHKaJ/H4Y=; b=RY8uony7PE0tu4aR+VcrDOwAk6Ov7odDss5JHI0/pIqjHCP2gtQ5fBbIuLjff5m8Xo BeaxQZZg4Q9pE/qwv0vQSPbFA1Hq0W1WUfHCM4Qgn50ami87w2UdulMTNcMphOLwvjTv 0KcOInS5riSiVeTcjFodjvdfdQSOD3a1vbbuCwvvdIeuSG5TSAKqOzOm+LJqQdFW/pOQ 78zA2CNr/ILHh034Atn5E4KfpftMscCun+KTXclBIEUij41XuClaFG3Q0uDyHs3cc6NB Y8w8loBaTsUjQQJu0/b0px2UpWXCe/RT/aye45Eeej/mli6JWZhd6WH8MZVJDt1SATDt pbZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cy1si22781169plb.429.2019.03.01.05.28.18; Fri, 01 Mar 2019 05:28:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728347AbfCAN2S (ORCPT + 14 others); Fri, 1 Mar 2019 08:28:18 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34748 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728290AbfCAN2R (ORCPT ); Fri, 1 Mar 2019 08:28:17 -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 A2A4516A3; Fri, 1 Mar 2019 05:28:17 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 92C583F5C1; Fri, 1 Mar 2019 05:28:16 -0800 (PST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, mark.rutland@arm.com, Will Deacon , stable@vger.kernel.org Subject: [PATCH 02/10] arm64: debug: Ensure debug handlers check triggering exception level Date: Fri, 1 Mar 2019 13:28:01 +0000 Message-Id: <20190301132809.24653-3-will.deacon@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190301132809.24653-1-will.deacon@arm.com> References: <20190301132809.24653-1-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 --- arch/arm64/kernel/kgdb.c | 14 ++++++++++---- arch/arm64/kernel/probes/kprobes.c | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) -- 2.11.0 Reviewed-by: Mark Rutland 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; }