Received: by 10.223.185.116 with SMTP id b49csp538379wrg; Fri, 16 Feb 2018 03:12:44 -0800 (PST) X-Google-Smtp-Source: AH8x225QYJ1bLfI9bOyntagbCpZRVL5wHytwmXQVe7i843hxNKlkcZ5ZPFHqJLnJHEp3X1X0Jd0H X-Received: by 2002:a17:902:6716:: with SMTP id f22-v6mr2689220plk.180.1518779564397; Fri, 16 Feb 2018 03:12:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518779564; cv=none; d=google.com; s=arc-20160816; b=LcpJb5KZc81CKLOvgtpJDs5d3key4/tpwh+7gen9F10UDnjIpOIYHUlJ1xy1ytaXY8 jOCrtSZKvbiMqUhhXDzO9pxmzxLUzFume8Ubtwcdsik65yZlq5wCIVQnn+6dsMBkGljL IsGv2a0j0wwmU21U2cyC+LbK3EahTnt03XD/NBEfFMBu4ETw8EQvhd8lLiViToWURMbR HrgJfk/ul0NaCi7VyWa3ebutNmIz+0x4cT/YOGEDbvu+rpXsJQi6dlQFp+aZf7pXcjIY AD0zwt7F76+1CEJH6FwQxcReQ07/NdE22FyJzLJNX/VTOT+yz3gUmIsmaRnx0VNqZSOz PCjw== 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=1wgFIfW5X5ZcfpuJxoIOYLtzJjS3Ptb3pliisbZlumQ=; b=e4u02gKRYNsXdLpr7Nt0gcIzSQ9MJnUaH7//F3UtRbegaGcFz/dFtjkj4YOgcjb3Is 2Yg4fldumKdw30qPq6VutIitdEBfInP74+DMkJ+dLHg4dl7TjH48iWpEbslbWLgIbagC kCsV5EIiSToL198ZEldvoiFhsVs9AXDzMkBKMolrqtVGnkkGBeHVEysdSptdNXTImrrD zIzzyA6nB+vbBjOY/vx3uegbe6AV5FOkwA3P1wRDP9IbLMxBQN9KeYbQ5SKRrZOkmdfG oWGG4+cp5EjKAQcQPOx0YkyH+jAo2RmBzifNjCL4CCjuI+V/atH8wUNWG77ICrs+NnuS pXQw== 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 b2si2813394pfm.409.2018.02.16.03.12.30; Fri, 16 Feb 2018 03:12:44 -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 S1946065AbeBORmt (ORCPT + 99 others); Thu, 15 Feb 2018 12:42:49 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56282 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164144AbeBOPcK (ORCPT ); Thu, 15 Feb 2018 10:32:10 -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 46F74F8F; Thu, 15 Feb 2018 15:32:09 +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 , Ard Biesheuvel Subject: [PATCH 4.14 060/195] [Variant 1/Spectre-v1] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 15 Feb 2018 16:15:51 +0100 Message-Id: <20180215151708.721857361@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@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.14-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: Ard Biesheuvel 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 @@ -103,6 +103,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 @@ -376,6 +376,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 @@ -884,6 +885,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