From patchwork Fri Mar 9 09:06:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270139 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 67AD260236 for ; Fri, 9 Mar 2018 09:15:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62C7F29DA0 for ; Fri, 9 Mar 2018 09:15:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55D5029DA2; Fri, 9 Mar 2018 09:15:27 +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 C17ED29DA0 for ; Fri, 9 Mar 2018 09:15:26 +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=vDfNLzx5yOBjxHL3nEG7ZwQl7lB1qUTMzxzyVvo0MOg=; b=eobLtkw8Ao7Fxmk6i4XIV6LG3p o7KivtrfwfgwiehkKJdYQuNyFrOwDdM5DKErLderMhcOkUxKyS1ysYB14M0QL2kfV1YjhxOi2XHup M6IQLxPZZUrH07ygg2Jhh+3MjDWWOjd5ngz5KTlxplqoE8inXl9D3YzRAMJjilN1Pp/adq2IrBoRU qF9OPOImnr+0E9WCaUoF1DOOyHsCqaW/oShI6cnUwvXcvUsfsk2MGCDtTd/yhmrnFh9bMqlW2y+4e jyydX2Dm+rzkyTmMK8xp/jmJ//N5cYi8TVhbI6RB9FcgdieLtUL+Vx/pW/9dIz1y4d6f2Cj655tVb l7pzp6jQ==; 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 1euE7U-0000jR-0g; Fri, 09 Mar 2018 09:15:20 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE2N-00048t-Dt for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:10:46 +0000 Received: by mail-pl0-x243.google.com with SMTP id v9-v6so4917515plp.12 for ; Fri, 09 Mar 2018 01:09:53 -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=3k9x4gszDF1Sl2Z5MR8HI2rxZTAw7E1DFlM5X0xtUPs=; b=BWXrbSQxoAV7L8OEdIvoFSRKn9KkuEEiTV+FNj4IknbsDuI1G4ga70ux7rl2TNE9vw pAiSLIOhpjtMZRQPBA2Gzn8UzJMa3Y+9Jxv6X4nUgezIx34ngkcgqBqjctxbyO75UoIG lbh2zG2q06qw7L7Yk8NnT2wAT7XvfMncAoF88= 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=3k9x4gszDF1Sl2Z5MR8HI2rxZTAw7E1DFlM5X0xtUPs=; b=XleRe74lwq7j3gy83V19mlfr506m89DmDhor3+NZbOMw+eOh/Nn4zs6Jm3DY4ACcmT MIu/wf3mzorsFYGRIfiPzc2R0AgZGMISxmEAoidSz/LNc3GalJn8LpoegX5FvTFE5X5r frkk1ufqFSbC5qR4urgtX9e1jnC8+I4X+jeAMjUIyemFU6eOVhGxtkPA/DTrNbMGy7E/ 2A2bhSYWyKZt27VjlUHK6p8myMKOPFx2cKYAJPd4uf5XZqOdsp8ZA10OIWN8QGgedJlZ xFCaZAdNIsP2pDBuPuvQEGziiJtSA8fZHr168kwR8rFMkZInfcH+AGM8PpB1vGM3ZT7v HhgQ== X-Gm-Message-State: APf1xPDm0m5l2ol2GA1m+b0J9sKH1yNWFsArhmrqw+9ZJKezX6VAYATl XVizbihOxA8ES4JP89Z8NyntOQ== X-Google-Smtp-Source: AG47ELsoXqGQkFozsocjLZVbsZ8I9GImK3fstUOznB1ZbjQvWMcjlNQmjYby4oKdvcaacv/MUIfzNA== X-Received: by 2002:a17:902:63:: with SMTP id 90-v6mr26556438pla.125.1520586592685; Fri, 09 Mar 2018 01:09:52 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.09.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:09:52 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 16/39] arm64: entry: Apply BP hardening for high-priority synchronous exceptions Date: Fri, 9 Mar 2018 17:06:59 +0800 Message-Id: <20180309090722.26279-17-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_011004_481891_997AA13E X-CRM114-Status: GOOD ( 14.13 ) 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 1dfbd9023777..bc62f8d2c981 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -530,8 +530,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 8a4e0a317edb..b1f084dd7b6d 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -561,6 +561,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), @@ -612,6 +618,9 @@ asmlinkage int __exception do_debug_exception(unsigned long addr, const struct fault_info *inf = debug_fault_info + DBG_ESR_EVT(esr); struct siginfo info; + if (user_mode(regs) && instruction_pointer(regs) > TASK_SIZE) + arm64_apply_bp_hardening(); + if (!inf->fn(addr, esr, regs)) return 1;