From patchwork Mon Feb 26 08:19:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 41BC160386 for ; Mon, 26 Feb 2018 08:31:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ABA829AD5 for ; Mon, 26 Feb 2018 08:31:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F24A29B17; Mon, 26 Feb 2018 08:31:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A38EE29AD5 for ; Mon, 26 Feb 2018 08:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2ixrkpNtyV11q/6FgJxkXS6b4L2A1PYDTIitMpH75TQ=; b=Rn35ddmCmp1RMe 8vWVqV4WcKtXNzJd/PShuQeA1WU4G4lqK74b1eeyGKwJcSSw9Xe2pLVfw9c/Ed5KkDdJXtcoelQlV S3NQjucWMZiJO7+P5FkhsdBO1rhfF/UonbXovcAQOFwpI4Hk0rHpwRx5jRCs8fB10AvvpeKYeHQdz LT4vhMQz+PTQjJ2tsDqKgAVOeCYDBM/UC3Pj9ETPUDY3L1G5nSbUI3O3oGj2f8tMpAzB/r+7aVacN /brSaCXNZ+gkIGBxlP+xV0tcEDSSfZxuI7XqzAXI3U5EJ7mV3hyU3eFhsqZbFVW0BbzrG8npEyCnw rhYxxy//TStmjx7pA+nA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqEC5-0008M6-N3; Mon, 26 Feb 2018 08:31:33 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE3a-0000rJ-1k for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:23:35 +0000 Received: by mail-pf0-x242.google.com with SMTP id c143so6222868pfb.6 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=I0NcpOMwUpRTdh4kJa9xm0wnQVM6fayAelXsCOInWd+DTTuoCX81zyxTha+4U4LoQb nKJhmCrEDL0OUbR0MnEYt1/rEW5TFdqWvAgEXvI15wQQRvYJ33RxmRJuT741SvNLPX5U IroBGgrONcDJgqE8syQDqtHYY2i/CiWbvBrL4Nsu64xecm9zjOnweDbqgvcH26YR6pNs DWmlkuru8Iu7K+QrLTEjHSbfJ5Bu0hkCztOejjuFjjGdCI2EQhB8NVSvB/Ad5cPZ4uAN yAgLVMTmskRHu5R0qy9clRSiQ/+GiqUNZPG1XGDpiVeb7KOmNpwhQJa7l1f2Wk2DqMyi Rc1Q== X-Gm-Message-State: APf1xPBpXmdZlivx3CcfvSP8Ou1yjzgwuIgOplmogBf72ANSBbBFUAlo zoV3/ADNrzaqQbwOVOEbmrwFKw== X-Google-Smtp-Source: AH8x227cgyhkICptFyc3f3w+5c5qFNMjmqE0Lofohde7V156XP1zHpApYtehiI2PCxrjfZoWjTWzAA== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_002246_717621_C8FE53C9 X-CRM114-Status: GOOD ( 12.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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