From patchwork Thu Mar 1 12:53:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130192 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2761566edc; Thu, 1 Mar 2018 04:56:54 -0800 (PST) X-Google-Smtp-Source: AG47ELvwwaiNqWibhUS4ug0ojC4m0EV8O3i6JlQQ4L3WusE7igRY/VYbaUKl+xggutAz52lVqZM8 X-Received: by 10.98.245.131 with SMTP id b3mr1891728pfm.20.1519909014665; Thu, 01 Mar 2018 04:56:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909014; cv=none; d=google.com; s=arc-20160816; b=im7/lJxa2j/7ajYE/8rmOWlPsYSpBp1cLyXjuZXA5JVNZ9MkI974ZhhNCw0gzhec5r aK2Yw2CVzvYDqeSv6BJjmNEiUJCjhJfbAUHRQrhBJbSl8DsHJ8n2YB0tN++8PJGmFmKR wbT+lsnCnWW3JBcWjSddk5IrxOwaFXVEBLYtLDzT/gJ3bp+8pla0Wd5+uhWBGuU8ylJl 0FpOZfu01hzla7MtoTMhULbwFgS78ih9sJ4SjTqwGiQeE7x8PhqLLTN+mXIeuLWq4buG +RrJnrX1qYz++veegF0iEeKWTpac4ULeQnI+mTrLH2WDl8aamAKmtpUXB2DSeIG1gxWH OSig== 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:dkim-signature:arc-authentication-results; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=MhWnm3ZMeZe8r9Gc9PLcIAlb4fe/x+5KmKB7R+ik2ySDozE1pUAtQ91e/057q6u/FI u+Qu1uMxk0jLVJIOiWRJIbhxCoIcAabLeb2ve7FTGgb5fH7uS+M2rseu7sdF+tlnd5DJ L+MtIDGLYYeEmOLPAoNXT6asqfv7w5hsT+et1vm2qbn7XDtfKundg3XzmiCZBaR3PmuR 4hUhxhIIVeFEfsjxo31P9Cr7ym27010l+1V85/CgQUtJ4CSwERcS2PR7WmeQ9H+TxKEg o06Ms9Yy9xYBnFWk5n0U+KkayCNqd+kAfHSjvC7N563evcro9hD+0Zcy76WZ85ziHO71 QOOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kIYle+vW; 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 q18si3011014pfi.105.2018.03.01.04.56.54; Thu, 01 Mar 2018 04:56:54 -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=kIYle+vW; 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 S1030773AbeCAM4v (ORCPT + 28 others); Thu, 1 Mar 2018 07:56:51 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:37817 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030576AbeCAM4q (ORCPT ); Thu, 1 Mar 2018 07:56:46 -0500 Received: by mail-pf0-f195.google.com with SMTP id h11so2008080pfn.4 for ; Thu, 01 Mar 2018 04:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=kIYle+vWacd0WWpBliXR7l16/dddPTbZmm1Rx4E2dG+3u/1jdUn/IZLWWUyyfxr2hD El+MuyFgxNPXf9XL3tvpmw9pZfB8wEs/RFZfiW5fCoYQvuuwfbryin7ygf9dAdPebEQ9 9QiUKfqJO8e4TUcz4GfrVMSI1MaJ+kfg5X4ZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=O3wTB5rSEA04gNhaXqUa8sYKqvu5bxeY3kSSQ0LmNNFEV+eJU29dkZAFlvS0IGLAE/ 9cxmNVZKZUDn2qUdNCwTVshaOkJMr6v9iac16anB6lYr+HhjVeQmyWyfJhHyaGh/YymZ jh8HpklqTAJGLpoZMDf28kkegLvl7OTc+K9v9nKJkxY2gw40ffRykxyfqHUpnXnkLjm/ KAQDgPRWhj1CxV/sSdt4QL0OiGYVlX1pyU/h697/NVYwpYqp7Mlz4seEDsxjLMc/yg8Y JEOnwIj33gFLiIa3GOCV+L+Qjy5cJMa32Oeojf/nAnQdsSwyhqBm+P/vzkCcWwK+S1C4 sIhw== X-Gm-Message-State: APf1xPAkM6tadQO4H6EwlmOVsdFF27IEM8OnUoX4Nf+/udglpwMEnDh3 mozFkcDlArF2HvAKvQlzBVDEG6pCRN4= X-Received: by 10.99.178.6 with SMTP id x6mr1526018pge.98.1519909006247; Thu, 01 Mar 2018 04:56:46 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.56.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:56:45 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 12/45] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 1 Mar 2018 20:53:49 +0800 Message-Id: <1519908862-11425-13-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-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(+) -- 2.7.4 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