Received: by 10.223.185.116 with SMTP id b49csp3488228wrg; Mon, 26 Feb 2018 00:24:07 -0800 (PST) X-Google-Smtp-Source: AH8x224/Cf9Sgg2fDSzY/nr7ETo/mQFZ1PZOlVcFKEExiMybIkB/o3dKvnEanGLwuhfaAHjYVjZ6 X-Received: by 2002:a17:902:3a1:: with SMTP id d30-v6mr9695356pld.409.1519633446902; Mon, 26 Feb 2018 00:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633446; cv=none; d=google.com; s=arc-20160816; b=NbKN5gyN0aoW12rEPJYaClpgk1tpx+gCVN1dsaOzJ5f9Wtnnw2fvQGjniI636YjZEH lnkfrVqCCZPd6c8yg2qELQz8k4n1beNtK1DrzHKbZlul7edyjB9ebr+MrMviMasRdF3Z u3BtPUV6TnmhUolEdSp602vtCEjwt/Teas4rgXARet4TAtkSf9sq7vhEmVOiu3Xxua8/ Q4nf6mW2ByKxFDG1yXRi/xxcFSAEEcsbMVw79Xwp0PrXC3RzSvZTLs7hcQy2qH73LwzM rvGn+A4fn37nejgLf+eb7bCllOv7NsuGKz85tYkwuVUgtadcL6KO/Z3MyYY074L1INL5 OqCw== 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:to:from:dkim-signature:arc-authentication-results; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=mDB1JR13H8ejA72ceZQ5cr1EsycXXugT4ex+7XaISx534ltuSYP5Q2IRICNcm6O2nw XDp2HRuWIdhV4Sz6y2suYzq5D+Hz3KsI1bNQBXjtnwiqOhjlrxSZgrNNrrplkiecOfYL JyU0Z3K326vbQIY20yddASb3hzkcRP/UAJa2PI8Zzr8yb1UbDiFILnvAq44r1oKJvXuK 0wrx7ZQEriALRZ3/Ag8YeezQLIm1IN2aB3M1RxGUH4Ig6SH9+RdYb8cEi4zvmsSbsBLy IytUVy0BYKJEWCFAXYFgzOX+q18BQY30Jy/8R57Pt+rR5m2Q6n8omCLY8grsDIK7nY5V 3K3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MDioq7zh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4-v6si6398736plb.282.2018.02.26.00.23.52; Mon, 26 Feb 2018 00:24:06 -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; dkim=pass header.i=@linaro.org header.s=google header.b=MDioq7zh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752444AbeBZIWm (ORCPT + 99 others); Mon, 26 Feb 2018 03:22:42 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:45458 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751932AbeBZIWf (ORCPT ); Mon, 26 Feb 2018 03:22:35 -0500 Received: by mail-pf0-f194.google.com with SMTP id j24so6216212pff.12 for ; Mon, 26 Feb 2018 00:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=MDioq7zh8inaTCPNZ072hhyYNNWki2OkWhxbwQ6dM+71A0eOxwifTmr1PNxSsMlCiB 28eHc0HPvTSAnZ3GOqiw9WtcGyugYYaGl8wORxByDQstGgjdV+17xi6wZMw8XtKBtPtw vaC1IdStpPgCtiKChJvYegndbU7nTrUhWU6Qk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=El9EUq4BsvT5V0oV19tdstpa7vY3K0TnQvOnRhqaXo5GaVhaHpa2qjW51PNr0NlddD b/f4p2dH5lbZDd3cMh6jmMaT9e3aDTEfEqa0Fqc/3wpfmz1xondmIqydsDg2S7GvyHYd Mh6IUGuw4mHJCndFer0Aw+dX0/rE4tuvb9duXSi6yTFRYK7DcOj+W4UoMfFYP5PLe1eP b4zXmZaktDd2cmqLIPrU4LzQvbeImXXANxNQTB4rffyDUazuUrDUUzEiA8/Ir5y6pw0q aNshhToa4kFxCw38af5BsioLxf1r1sqBD1pRu57ecV435kPUwWjd+iuAl59irBTFJiFR JNfw== X-Gm-Message-State: APf1xPADdTCHTM1LI8s3Evu1JzyD7p30lYx20g9DOBXCErXV+CdT9aVs XfBh4u+NL8smGVwVQbfqToAVyg== X-Received: by 10.98.245.131 with SMTP id b3mr9842362pfm.20.1519633355077; Mon, 26 Feb 2018 00:22:35 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.22.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:22:34 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 12/52] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Mon, 26 Feb 2018 16:19:46 +0800 Message-Id: <1519633227-29832-13-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Alex Shi --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 2 ++ 2 files changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index ab3a179..a109d30 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 48c41ff..0a27e12 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -233,6 +233,7 @@ alternative_else_nop_endif * 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 @@ -754,6 +755,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 -- 2.7.4