Received: by 10.223.185.116 with SMTP id b49csp83343wrg; Thu, 15 Feb 2018 17:05:31 -0800 (PST) X-Google-Smtp-Source: AH8x224co9duCbB2U0A9isDQaSplb0xdinAhoxOssDnPqo6Xx4RtW89IaL/fCUIUo4IxxstJT+U9 X-Received: by 10.98.153.2 with SMTP id d2mr4452073pfe.44.1518743131083; Thu, 15 Feb 2018 17:05:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518743131; cv=none; d=google.com; s=arc-20160816; b=CxGrMWKxzgrNtC3+q20xCg9RgdsDEmqyJyDSBdF9/OHyvtdY4va9xG/no+0zO+1CW+ rKOU7FPkbsU5airKlo0AVvdOceDR3xQk/fQgfXADkYk+9ADT+N7jqLyFT7iZPE1l5T+T zEcx22RoiSOBt6FX0exxUHmb+zpBoa95qCXhbHG6Hnu3iHyFBK3o71imLFXADO8GC/Fr qL8Zr0joLNVzTTRM53sL0R7Vu8v6n5vtujfr6FgPcV3htYplfO9j2OOOJRydQi1pwzoh gVQuF3QABhWcMqb21ObVihJzOmDtsuiZSSUW9Rf+Q+Q0HFUMG8UyvjxkY22JyIK0qMCP L6Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AjqPufArAALc9zRTgk/YEekF0mYqYH08r8DYC6Xcsto=; b=IsV1dsYvs+cNCwujgWiWOH+uC2kDN5EFRYu38W1f43Tb26z39/Z+l/UkUmXvwT8o+G Bzn9SRsYnOK1AbSYNpgtJtxPKWjpcscGqJjmsvnvohgNueIjLYWb5sUfZObIQ5vEgMYG L2rclaGB39bmxah+Bs6oxT6wtP8NhGDoTTBwXQChclxMIk4LUzVlBiyj/MGD2zgwuNsI mN/7OC6rinoLIaIYvFh2AxF4IHDz7rRIKKMtMCOwLkUUs9KUO7widLA+A4VOjL1rM/lV VE/FHzwGo4V5ZqgH78v9kQ47noX0nUnzZZ0/9jkwILW9d6eGVNBK6ZKKMCcJIAuzzO4N yMfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 o32-v6si467201pld.52.2018.02.15.17.05.15; Thu, 15 Feb 2018 17:05:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424207AbeBOPmm (ORCPT + 99 others); Thu, 15 Feb 2018 10:42:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:33366 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424093AbeBOPmg (ORCPT ); Thu, 15 Feb 2018 10:42:36 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id ED6E81093; Thu, 15 Feb 2018 15:42:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Will Deacon , Catalin Marinas Subject: [PATCH 4.15 053/202] [Variant 1/Spectre-v1] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 15 Feb 2018 16:15:53 +0100 Message-Id: <20180215151716.007874324@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon Commit 6314d90e6493 upstream. In a similar manner to array_index_mask_nospec, this patch introduces an assembly macro (mask_nospec64) which can be used to bound a value under speculation. This macro is then used to ensure that the indirect branch through the syscall table is bounded under speculation, with out-of-range addresses speculating as calls to sys_io_setup (0). Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 2 ++ 2 files changed, 13 insertions(+) --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -116,6 +116,17 @@ .endm /* + * Sanitise a 64-bit bounded index wrt speculation, returning zero if out + * of bounds. + */ + .macro mask_nospec64, idx, limit, tmp + sub \tmp, \idx, \limit + bic \tmp, \tmp, \idx + and \idx, \idx, \tmp, asr #63 + csdb + .endm + +/* * NOP sequence */ .macro nops, num --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -378,6 +378,7 @@ alternative_insn eret, nop, ARM64_UNMAP_ * x7 is reserved for the system call number in 32-bit mode. */ wsc_nr .req w25 // number of system calls +xsc_nr .req x25 // number of system calls (zero-extended) wscno .req w26 // syscall number xscno .req x26 // syscall number (zero-extended) stbl .req x27 // syscall table pointer @@ -932,6 +933,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp wscno, wsc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 xscno, xsc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, xscno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall