From patchwork Thu Apr 12 11:11:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 133201 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1571253ljb; Thu, 12 Apr 2018 04:12:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/jRiGEm2BAJvnW9iRABvabUe1zlXfWAerfJEMV+TMxiPCC7Tw+IMce2C/mpE2o32mKfkgJ X-Received: by 10.167.128.71 with SMTP id y7mr7298533pfm.12.1523531532468; Thu, 12 Apr 2018 04:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531532; cv=none; d=google.com; s=arc-20160816; b=ku5yT856IFSVtQ6h41758FrqpDUAxCM7lebKARlAijQyFMIASJbDiwUz0Itya9gBnY K9dJToFL8Ut2PQUNKWHpipYZ+bL48Kj28aZj9CJMZc49R2UFBrLVtVnrUJkjRIkHRMK2 LhNPG9yw2jr42obn5ceyLFOetmOxNN5AgG1PZ4N/jbET4bS/7+SPfX/eCAhJGEt+xkP8 52hH5tXSFRJJByG1JqKqmmINnVZJ+UwcQeq1BfmaYHCw0jdmYHsdkTF2fR7CuQarjvCY q3Wmr3L8Rl/Uumoz+vqWym9ztQ0EATxLKgYbdApcnUBW3qC1C5u3gQjoDgHllEe+fjGW NZGQ== 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=8ItJVYMKriuzehwkSylUkRP/cwgu5SKwbU0WfENwoxM=; b=Eqn4OKC5QJ/foLAEQpmQhYxlt1Ajr9/ZDqzrpGZpyTOfhXFmfv4jbOpfOZYqR7d/hn Hv3tCZT9PI4QEg8nnyYELSmuM1KO6qkJsoSWBqO/f4Gq7k4YucGWUDN+bmj91Rr5Fxbb jEYsMMJ0futXEjQ6I/cbJmnaW6jxZ2S2dWzZV9ZvsxvlL8HKB1c8NmvwAAjhfZvwT+xC DI3Xm5DgqVsvLP61G8qm+LrQnm4p/NRqIOsJknUJGewx/m15Mvm+rRkoDY4DXMPs/bhs 3tspHTUjUrLLMK3ONZfTCWfQkvKe9D/dqKPFNzUFdX+Zyz3qGUqW11BkNvlmL8eGU+b5 vGKQ== 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 bg3-v6si3001807plb.118.2018.04.12.04.12.12; Thu, 12 Apr 2018 04:12:12 -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 S1752777AbeDLLML (ORCPT + 11 others); Thu, 12 Apr 2018 07:12:11 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59346 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752428AbeDLLML (ORCPT ); Thu, 12 Apr 2018 07:12:11 -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 20B4180D; Thu, 12 Apr 2018 04:12:11 -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 7693E3F24A; Thu, 12 Apr 2018 04:12:09 -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, catalin.marinas@arm.com, ghackmann@google.com, shankerd@codeaurora.org Subject: [PATCH v4.9.y 06/42] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 12 Apr 2018 12:11:02 +0100 Message-Id: <20180412111138.40990-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412111138.40990-1-mark.rutland@arm.com> References: <20180412111138.40990-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 6314d90e64936c584f300a52ef173603fb2461b5 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 [v4.9: use existing scno & sc_nr definitions] Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 1 + 2 files changed, 12 insertions(+) -- 2.11.0 diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index b223b1b4d5cd..540c24f74837 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -94,6 +94,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 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 3f1cd7a795bb..c154b1608405 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -795,6 +795,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp scno, sc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 scno, sc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, scno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall