From patchwork Tue Apr 3 11:09:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 132721 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3666115ljb; Tue, 3 Apr 2018 04:10:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ZtznwCgvx4DmLp0cVtTrNBU5PHSnDCV4rn29dUIwO8bzQ/FJ8ffRKe45NNKAO54eNJ+yL X-Received: by 10.99.119.133 with SMTP id s127mr8704526pgc.441.1522753818703; Tue, 03 Apr 2018 04:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522753818; cv=none; d=google.com; s=arc-20160816; b=nh0/6sMV6+ZRiUDcc3buXH9cI2PCrn7bWgDmK+drsvT95s1eo0EdLnuV+vc/Qd3ciW +vy4swk50/GggokHAZDre0zjwEZz6QnTt6fZ5ac7y9wsyCbBoVtfUyTa3WZ4znreDGKy 0Mq0WLKDB6q1yH70V+/fScmAfesYkN26+RUeEbPbeWl3hCO59Q3UoTywpoikejnu561J y/AuOQbYV5+HGuI1IU8FjziXo9rsEicxncXKxvna7QC3ELBwMHbLoGZ6bqRyFZg1kDOF i96KhNmdshgrJHO4xPnTE//ykwOkXwY5/CqjlxJukzMj9Gnu0Rir9dmqoMYjmONpMCMJ WkuQ== 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=SyjfI/248zJ3zLzsfCokwWZeN30fAPHlRn3Kd9hKkzE=; b=0053uwverQHmmXuVz3uX29Vf9c+GE5UwJi8gzJdWU/zSD5yhOdEcVJpmzucZrAGonW N5wEOjQUvvBeDqzSeLZ1gsHYTIO2wbauXWTYWUOqHp/HDCs5mkpIs1rCYrQoRty0Cpgc n7IBh2yS7TyU/73ELuMxlZxmqVG/P79Re+q9y3m5AAdfqdzaqa6jbE+wSKFqz91xAbOQ qEhXsDd1U+eZtBh2xojeEhflgHaHbVGaWijU/b8J94mDwFTyYrZzltGkwPO8nI9e3/8c M+QVwzECP50BcdVKQtfcagy6xc9TENf9ZzXCHDEsfQGgNNOR4l7V9cJn8eWG4xZU6WaX 23Qg== 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 l91-v6si306341plb.301.2018.04.03.04.10.18; Tue, 03 Apr 2018 04:10:18 -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 S1755502AbeDCLKR (ORCPT + 11 others); Tue, 3 Apr 2018 07:10:17 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59364 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755402AbeDCLKQ (ORCPT ); Tue, 3 Apr 2018 07:10:16 -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 1995E1435; Tue, 3 Apr 2018 04:10:16 -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 DD31D3F587; Tue, 3 Apr 2018 04:10:14 -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 Subject: [PATCH v4.9.y 15/27] arm64: use RET instruction for exiting the trampoline Date: Tue, 3 Apr 2018 12:09:11 +0100 Message-Id: <20180403110923.43575-16-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180403110923.43575-1-mark.rutland@arm.com> References: <20180403110923.43575-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 be04a6d1126b upstream. Speculation attacks against the entry trampoline can potentially resteer the speculative instruction stream through the indirect branch and into arbitrary gadgets within the kernel. This patch defends against these attacks by forcing a misprediction through the return stack: a dummy BL instruction loads an entry into the stack, so that the predicted program flow of the subsequent RET instruction is to a branch-to-self instruction which is finally resolved as a branch to the kernel vectors with speculation suppressed. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi [v4.9 backport] Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/kernel/entry.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 805dc76517c3..f35ca1e54b5a 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -880,6 +880,14 @@ __ni_sys_trace: .if \regsize == 64 msr tpidrro_el0, x30 // Restored in kernel_ventry .endif + /* + * Defend against branch aliasing attacks by pushing a dummy + * entry onto the return stack and using a RET instruction to + * enter the full-fat kernel vectors. + */ + bl 2f + b . +2: tramp_map_kernel x30 #ifdef CONFIG_RANDOMIZE_BASE adr x30, tramp_vectors + PAGE_SIZE @@ -892,7 +900,7 @@ __ni_sys_trace: msr vbar_el1, x30 add x30, x30, #(1b - tramp_vectors) isb - br x30 + ret .endm .macro tramp_exit, regsize = 64