From patchwork Thu Mar 1 12:54:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A151060211 for ; Thu, 1 Mar 2018 13:38:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 910DF1FFDA for ; Thu, 1 Mar 2018 13:38:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8402C2040D; Thu, 1 Mar 2018 13:38:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0085D1FFDA for ; Thu, 1 Mar 2018 13:38:27 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0wkLD6I+rcGPeDre2vaGrBz1fDQuJOky1GFgJ9iW86I=; b=snEHcvZdfDCrGHYW061T65Kza5 y7aPjySXy4r0PMIZHI0ckWVJK8fCmS1T7/4p5x+93oX5n8qK5FYeUKvPxxOwKCjp8PCgHa3XPBP86 /Sqc75FGsYzjoGlPwvvg13QZ/nkKYUOf8u22bVtXzUR6sjLepfYYfbmNMp867gHtqWpGcLCqjStX1 lsaDMNxTtQNh+HS3BSSusL2g+kJZ1B9CLWwvcvcWzr4kEl3MupvDHhgJugF8Rrq+mW3NHXdQtqTJm kGd2MbGUnfoZ4TLFHo7wS7Xza82cSX6OcA9a/+dlut5kLYsTB80U4QZ9Q6fhe5RFcOFhnkD5nmGbK i/At7zcA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erOPY-00014t-R6; Thu, 01 Mar 2018 13:38:16 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOHM-0001sV-8B for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:29:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=YaNlfJjXAm7Tj4lsPJi0xUkj7+DnsswK/FzZeoAqgZ8=; b=A/ulqfbhJZxpwVLhti0ExXjyl GNdltct3W4CsmA6KoKzFFnayrS3UCCAnOsSemIkxTBVT4Zb8ieRtBkt/jOjSz7k5wSscZgMXpdLtg NWco/zopW75vB736eAHvHJU+pgheRKWbhEYvK7YmGl6m0Vy6K4VAPCiqq/AgkpNF1yhSrJHLttTJG Il2sq0tiS+jsTiMristBpPMnV4PTvdvowniIMkfD21mScZ0AsS3qTaebXqWCH8kcJJ9cXzV6gQIVN Tc3eGjADGOr6vhKXkTsL3qOmKp95C6XllluLBxxDgTYwo3V+EpLKbSaLQQsX2MDQnoaD1X1JAY9FH kYoYD3S5g==; Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNnk-0002Iz-DA for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 12:59:13 +0000 Received: by mail-pg0-x241.google.com with SMTP id l131so2275095pga.2 for ; Thu, 01 Mar 2018 04:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YaNlfJjXAm7Tj4lsPJi0xUkj7+DnsswK/FzZeoAqgZ8=; b=W450VjVULfESSLecI29my/KhkZfCs1kvm52qnoYBk7dus3/opeXMMtXc4bwKVr6C52 0nXc3Iy5mp3iecFj861l3leo91XXIkT4PYmQ1eHVX5MTAlCWacESDG8WTy/T52Ala7rd DmfInnzoyRim0YBzMnZOpYY8LzJPoRJFciJks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YaNlfJjXAm7Tj4lsPJi0xUkj7+DnsswK/FzZeoAqgZ8=; b=IOuPY65QtSTGzsi9RTrddAlx7nrEdGgu1J4wkALHdm5s8Dx2py+k8oaWWuCObValSr QC+nLsDsGeRgOR14aUsWzvFail3vVfb1HIPq7lPsV1Vehvbo9c2trf+9mgHTluQviAWE SZnRgtx6l+/1HGYJGWPU6SeMC35PEOm1/iZm7JiVHLs6exxqhcQMaPzO/gFC+kCbAEDp bUxbgeIEhKyrb95N7UJfu8dRwl6I9wF4Y9Z4SDlWDrhPDpa7Od/7J+HWA99Y15xYzLCf 9acFJZwe+JKaviV+IbdKttTxaerC8f3u6iD/xId49WgtDISo6+nHvjfY/Ovw2Xq3DmjD fjgg== X-Gm-Message-State: APf1xPAKAj7a6wNEnCtiyV7juDJdyBOKRV2JuIVKZkfSQlNtyhueLGA8 Yb7XfIK0y6rg/76cVffkJdX4yw== X-Google-Smtp-Source: AG47ELufBfLNL9+Jf+2D4t36mo1FgrZrKSQcICQzBdZ5rtW95TndtCUpLu325S11+fUv7s3kpJ5FfA== X-Received: by 10.98.172.18 with SMTP id v18mr1852855pfe.175.1519909139909; Thu, 01 Mar 2018 04:58:59 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.58.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:58:59 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 26/45] arm64: entry: Apply BP hardening for high-priority synchronous exceptions Date: Thu, 1 Mar 2018 20:54:03 +0800 Message-Id: <1519908862-11425-27-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_075912_940029_8477469A X-CRM114-Status: GOOD ( 15.54 ) 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: Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Will Deacon commit 5dfc6ed27710 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: Alex Shi --- arch/arm64/kernel/entry.S | 6 ++++-- arch/arm64/mm/fault.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index bdb0139..d50c2fe 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -584,8 +584,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 + msr daifclr, #(8 | 4 | 1) +#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 c95b194..6120a14 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 {