From patchwork Thu Apr 12 11:11:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 133216 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1571997ljb; Thu, 12 Apr 2018 04:13:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx48huI0HDVjFS5y1u+aWp59aKZ/fZou1TfXKNnm0YomeY0tZ4E2VNTZ081ywKfLP86ye36uh X-Received: by 2002:a17:902:1744:: with SMTP id i62-v6mr572233pli.62.1523531582032; Thu, 12 Apr 2018 04:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531582; cv=none; d=google.com; s=arc-20160816; b=CuCOxJU7IAwGaSADFBRFChaYjtracko6jUl7TqAUQzlqOzmJDMlHn9sNXM/N61JhFY KnPmSCCdartNN8TNItDe117spiXynCBuK1DTDDZoBjRWRR2AR570jf16BjrWFwfoCM2h rkU3SHWNF8bqXB+PK4nF/jvXq31SJATy3UK9s4NEfcfmIxtdDQ1E33MVZU4tKjR8OqKA igSUdIlCS4IqmimAOjwJN9d9gMIpj2g/2wGtIR/aNG9+W08wmdwnjUjaNy89oLiUP1LY lDm3Q6nd2SBRXvn/lQhPUzKk6FJkO7skZGBPWZP8I4zcN+aN+5fbzyp5o/rEHjWL0Ch3 DaAw== 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:arc-authentication-results; bh=9rwxS51ItHC5oe1peGb/bEcI2pEp8wkKAmRTl7tktFE=; b=0mz8Wq/mDCAMamSKFrHsBuivTIUZd8zPpMW4kYZMaB3E1+uKKOLoraHS+8nqX3x7os obhadFcietoguFk4FnRpXVPWiMAFwIP146eFdsMBQcoZuP1sh3FQLcrp2fXv+xdgT2AK BpCwBZ7ouUBmHpwOiXUUcZc95XIiVO+D0O5mWc93U/Q3+B00fY1JEQPfG5T26sJTQeix lhpunx6b84zQ2fUR6YOWz/A2zLT4MLRhAwOKSa29VroIYhkqfNrnI5f80EEE1OFgydnb nWNUc+qU0L2OkCN9Wc3VJ28qy4Ym/F4CQX2VeJqAQeDFbsD0Ni5JkEwcvdmjMCkOk4RP z85A== 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 bg3-v6si3001807plb.118.2018.04.12.04.13.01; Thu, 12 Apr 2018 04:13:02 -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 S1752918AbeDLLNB (ORCPT + 11 others); Thu, 12 Apr 2018 07:13:01 -0400 Received: from foss.arm.com ([217.140.101.70]:59496 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbeDLLNA (ORCPT ); Thu, 12 Apr 2018 07:13:00 -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 85F6880D; Thu, 12 Apr 2018 04:13:00 -0700 (PDT) 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 ESMTPA id DAC093F24A; Thu, 12 Apr 2018 04:12:58 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, ghackmann@google.com, shankerd@codeaurora.org Subject: [PATCH v4.9.y 21/42] arm64: entry: Apply BP hardening for high-priority synchronous exceptions Date: Thu, 12 Apr 2018 12:11:17 +0100 Message-Id: <20180412111138.40990-22-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412111138.40990-1-mark.rutland@arm.com> References: <20180412111138.40990-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit 5dfc6ed27710c42cbc15db5c0d4475699991da0a upstream. Software-step and PC alignment fault exceptions have higher priority than instruction abort exceptions, so apply the BP hardening hooks there too if the user PC appears to reside in kernel space. Reported-by: Dan Hettena Reviewed-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/kernel/entry.S | 6 ++++-- arch/arm64/mm/fault.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index fd6879d98bd7..30f4331d477a 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -624,8 +624,10 @@ el0_sp_pc: * Stack or PC alignment exception handling */ mrs x26, far_el1 - // enable interrupts before calling the main handler - enable_dbg_and_irq + enable_dbg +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif ct_user_exit mov x0, x26 mov x1, x25 diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index c95b194d1c6e..6120a1486054 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -617,6 +617,12 @@ asmlinkage void __exception do_sp_pc_abort(unsigned long addr, struct siginfo info; struct task_struct *tsk = current; + if (user_mode(regs)) { + if (instruction_pointer(regs) > TASK_SIZE) + arm64_apply_bp_hardening(); + local_irq_enable(); + } + if (show_unhandled_signals && unhandled_signal(tsk, SIGBUS)) pr_info_ratelimited("%s[%d]: %s exception: pc=%p sp=%p\n", tsk->comm, task_pid_nr(tsk), @@ -676,6 +682,9 @@ asmlinkage int __exception do_debug_exception(unsigned long addr, if (interrupts_enabled(regs)) trace_hardirqs_off(); + if (user_mode(regs) && instruction_pointer(regs) > TASK_SIZE) + arm64_apply_bp_hardening(); + if (!inf->fn(addr, esr, regs)) { rv = 1; } else {