Received: by 10.223.185.116 with SMTP id b49csp7393269wrg; Thu, 1 Mar 2018 04:59:29 -0800 (PST) X-Google-Smtp-Source: AG47ELtLjJbxgQ0j7cCR1j+JVSNH0HMD0cO3P3PlwlXroPhSPZwvFba3ngJ6RGEnvBHEnt0udUup X-Received: by 2002:a17:902:b40e:: with SMTP id x14-v6mr1588560plr.442.1519909169762; Thu, 01 Mar 2018 04:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909169; cv=none; d=google.com; s=arc-20160816; b=zHxOSTqup9eHsXJ3dov9hA87g13DMwOSYHkHs5D9kIKAlh8CUoEsUnuyKTiFWLZjzx p7qXcgRvpPrrKC5Jx+dOEBnXVwUsyEX+YOwIdJuYXatqI8nDK9GrYxwNGcvPcMfJxmHU K0Qnden31lOavKhZ5ZpfuZOvsI4RJsrI0LQps8BDYZuqQvehBpsQHziRKYitcOKMcyIg bfoXzTfBqHqiciJ1GNO8/61LD6lh07uYKOpMuOJ2VAoUmbK5+Zr+Me/gdSl2assslq6B 02IAcyblV5JKv9v5fyqikJKY8fjkuSHFLmKxkan9zxpmr+cCLHulsZHiFhFQmDHqp8Fp rGIQ== 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 71-v6si3053517plf.575.2018.03.01.04.59.15; Thu, 01 Mar 2018 04:59:29 -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 S1030770AbeCAM4v (ORCPT + 99 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(+) 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