From patchwork Wed Apr 3 10:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 161690 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp149877jan; Wed, 3 Apr 2019 03:31:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoH2Dbtct7gtgd837jac8OQoR6ypY+bIA86MIjBJJbLI4k/yDlpvLbO5rLKZt4oCO9HiBJ X-Received: by 2002:a17:902:2e03:: with SMTP id q3mr74645062plb.166.1554287485292; Wed, 03 Apr 2019 03:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554287485; cv=none; d=google.com; s=arc-20160816; b=WnKkKbrj5/D75bPG7lKZEQlXt63G9pJjJNFODcwr+k0cHAvxqnKxEZU8g3yvzSChuT ic3vmF00cLag0ZC+XrXV6duNrQvehxZ3I1jzn1QAo90GRu6D3EYXFAh/vMPi/7cTPd9S 3nMcpgTOSehuPgvQLRK6eL+QHU75aLeVUx8YygYVFxgme3aIy1PFiAeO0dfKNnPQwrQs j457gArxKdsf7cNx4amht/24y6js1POqCt15xOBz2edA2tNEx5EzZDQSwXI6aA29aDAt x928k4gUapJwLw/xCkVmIGhiQDNq5sE1kWhk6Y1Y64YRDawQ6d0CaJ4cQIaFc8sEMW8i C0TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=LJpKVnWKK7ieWKkifoZv6ipr90yJp8BxZ3+S+7eBx48=; b=Ut/zjyfc6eQSXWusqpehoM7DV14n4cfhgw7rOEVRmg+rvC3mESaDFBEWFLYh/XHOs6 +KpSHctrOEdzYrCZBEe/oOF4b6bxS7ULbSwKEJbUfWFfW3OS7t7LN/Ic4JMN1/4CwB6V gJ7eJ3vlXDHkfKSAWxHYv7JqJhDSG0lhAYJBdv7hesfK7inOr1EdCdbWnFiHp1o7qfOp 6DVxusT6+WU35p5EPgGj8XYR4G1lTXFUc/DffjsMvf8eXBoMif1NEUvXwxKb4UwA+KAi DXwZJFCiPCTO0g1aoOatwuD81vJ3ZYT2eoAaRTV409tkoN2xk+1LLatchIaATmAfiq94 mDBw== 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 x6si13185866pfa.59.2019.04.03.03.31.25; Wed, 03 Apr 2019 03:31:25 -0700 (PDT) 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 S1726328AbfDCKbY (ORCPT + 14 others); Wed, 3 Apr 2019 06:31:24 -0400 Received: from foss.arm.com ([217.140.101.70]:36996 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbfDCKbY (ORCPT ); Wed, 3 Apr 2019 06:31:24 -0400 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 A4BC080D; Wed, 3 Apr 2019 03:31:23 -0700 (PDT) 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 7066D3F59C; Wed, 3 Apr 2019 03:31:22 -0700 (PDT) From: Will Deacon To: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, sashal@kernel.org, Will Deacon , Catalin Marinas Subject: [PATCH 4.4 BACKPORT 1/2] arm64: debug: Don't propagate UNKNOWN FAR into si_code for debug signals Date: Wed, 3 Apr 2019 11:31:13 +0100 Message-Id: <20190403103114.29050-1-will.deacon@arm.com> X-Mailer: git-send-email 2.11.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Commit b9a4b9d084d978f80eb9210727c81804588b42ff upstream. 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: # 4.4.y Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas --- arch/arm64/mm/fault.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 04c4b88706d8..89abdf9af4e6 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -589,11 +589,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 = debug_fault_info + DBG_ESR_EVT(esr); + unsigned long pc = instruction_pointer(regs); struct siginfo info; int rv; @@ -604,16 +605,16 @@ asmlinkage int __exception do_debug_exception(unsigned long addr, if (interrupts_enabled(regs)) trace_hardirqs_off(); - if (!inf->fn(addr, esr, regs)) { + if (!inf->fn(addr_if_watchpoint, esr, regs)) { rv = 1; } else { pr_alert("Unhandled debug exception: %s (0x%08x) at 0x%016lx\n", - inf->name, esr, addr); + inf->name, esr, pc); info.si_signo = inf->sig; info.si_errno = 0; info.si_code = inf->code; - info.si_addr = (void __user *)addr; + info.si_addr = (void __user *)pc; arm64_notify_die("", regs, &info, 0); rv = 0; } From patchwork Wed Apr 3 10:31:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 161691 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp149993jan; Wed, 3 Apr 2019 03:31:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWIXHufCPuyK3rBrz6xMfvEyIZeuMT5FFpqGUoiXhgst7P4HSz7IG3wQ1XtVq7fgh0RP8m X-Received: by 2002:a63:5a4b:: with SMTP id k11mr71557200pgm.119.1554287492308; Wed, 03 Apr 2019 03:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554287492; cv=none; d=google.com; s=arc-20160816; b=kTgw/a/ptPEK02YN7V8ms/zWy1dzys22C2Zs8suyYoLGzr94FQt9YQpdkXL4DDfUxd /EWUxnD58imNjrKGowKN6CBDJZ3Y4RuPKrNIDGBcNi3s+vpUpFL9KvVIyBf0pUZEsq6+ ko11O5XaMxEiWJgqFx6wVBEEFx0WuaG/zyvdWYelxYuiythtzsajVx9tS4W+IfLC5lsk ViaZPRtNQhIEyLga2TK38CBuVmjape05PGj38TaIcwIQZcisM9FRUxusxLB7Ztxa4mYc Zmy9o1KLWRvJvTeVpzMasdoYpGjF1y14u7nwdpZC/eEJvwIi+FHz3T9JLyF4h1yGcrhZ nDAA== 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=jJ4yhJO7V7Zyd0ryQSbsM2P0QXemDxcSWjFvKP7xyao=; b=TIfGeArHLjYDtjDX4Jxh5pva7pK8EtMwvu2f2D30TAbldxL/EIupasz7UlpYhQRSgh NS0HAKLGJFiqVCtbCqq36Dff9lJUNeOer61+BKPNTasumRMHKkiGqydDvM0a84XZu8qi +g0AcQlMnMrI2Ovml1u2vwMVEWbCZcDFHSfuOSOQE8UZcvtXU55BPm9SJ9TuTSPHUbVC tPrRCIbqaLeFYGdDRunm8fc4M+hW+pA0p5UVGVic9LCV4huaqRJTAH4LPhC5zHPCWbR8 hVuXboMu3E5kVxv3URRgE8hO7FcE7bd72Se/8KIdqbjH13iWpzbLybfsnOHpfWCDj9JC +xEg== 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 s34si13630095pgl.97.2019.04.03.03.31.32; Wed, 03 Apr 2019 03:31:32 -0700 (PDT) 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 S1726471AbfDCKb0 (ORCPT + 14 others); Wed, 3 Apr 2019 06:31:26 -0400 Received: from foss.arm.com ([217.140.101.70]:37004 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbfDCKbZ (ORCPT ); Wed, 3 Apr 2019 06:31:25 -0400 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 2202E1596; Wed, 3 Apr 2019 03:31:25 -0700 (PDT) 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 E22443F59C; Wed, 3 Apr 2019 03:31:23 -0700 (PDT) From: Will Deacon To: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, sashal@kernel.org, Will Deacon , Catalin Marinas Subject: [PATCH 4.4 BACKPORT 2/2] arm64: debug: Ensure debug handlers check triggering exception level Date: Wed, 3 Apr 2019 11:31:14 +0100 Message-Id: <20190403103114.29050-2-will.deacon@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190403103114.29050-1-will.deacon@arm.com> References: <20190403103114.29050-1-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Commit 6bd288569b50bc89fa5513031086746968f585cb upstream. 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. 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: # 4.4.y Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas --- arch/arm64/kernel/kgdb.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index bcac81e600b9..f72743dc070d 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -215,22 +215,31 @@ 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; } 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; } static int kgdb_step_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; } static struct break_hook kgdb_brkpt_hook = {