From patchwork Fri Jun 14 03:07:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 166745 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1505367ilk; Thu, 13 Jun 2019 20:12:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNboZE4pzWOUvecc1dR8hyV8lc7Q4M1NtkNyr/Rid/alSltE9hDsU4J52ssq/+Cj704/AG X-Received: by 2002:a17:902:b94a:: with SMTP id h10mr91088076pls.265.1560481934175; Thu, 13 Jun 2019 20:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560481934; cv=none; d=google.com; s=arc-20160816; b=VxCgaQg+82EKpMHzAOx8UkHPXlAzuVc+lrdU3u37eeOzl2w4d85iASGd5KtsyPHvWj XOF2Co+4UFhKI3hPBkuAQ5m2u9gLxvWayfeioFhghv2ZKiU2IzxQoA9VHOQH9cvxCwMu St9Ry/VXgbR6F96AhZbQWFXfnlFaAaASndWzFlPJgX0Ibhf57cEYpddtil6mNc1TsnCW C8TJv92XAv7ZQr4bxvtuZumnNZAN+mIrPZnTCej6qA6p96pcSwxpybalW5PY/8yQfJk1 JrFIEfIGvyJq5fl/7x8BYX9n2Xjlnva1uEuWHony6fYaQiLyNyAiofyqqNGvFCVxW1d4 c2IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1IdhsUs/fdllTh2EJ+ScRqWrO1uX9GsPUvP6PugnTR0=; b=FclJviWZBUvypoYVORHJ30SN/OH1DCYQYUGBIps8y/y1v30ZGZzDClR0mT2jVScSJi 9j2sAVr3ZL5gLZY6Cn91qq6u5O8rjow0S3fXy4yiI9ZYSo+ES4eQMHdZaBdIkYbJbT9J zECA1TZsn5Oo9TY34Vnx5cCQUMyG1/J+ac5bJaks1qcj9SlR1It7brqjIxYlpqp8hqev PbQIIO9J8Kw/puywrBENaIPEfvz2vfxD7C6BeP+uNs3r6s+ddr3AdAlNswGWLT3n5JFS 9DkNrInm7UOPQVEQewJFLrc1TwC/0dL/gX9NCuAwgKKq3Brkhx6zoIApAXByPuiMOLVn 90Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CeEm6Q1H; 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; 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 e8si1073936plb.420.2019.06.13.20.12.13; Thu, 13 Jun 2019 20:12:14 -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; dkim=pass header.i=@linaro.org header.s=google header.b=CeEm6Q1H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725972AbfFNDMN (ORCPT + 14 others); Thu, 13 Jun 2019 23:12:13 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44892 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfFNDMN (ORCPT ); Thu, 13 Jun 2019 23:12:13 -0400 Received: by mail-pl1-f193.google.com with SMTP id t7so365351plr.11 for ; Thu, 13 Jun 2019 20:12:13 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=1IdhsUs/fdllTh2EJ+ScRqWrO1uX9GsPUvP6PugnTR0=; b=CeEm6Q1HCBNewplA3EEpKwApVIKTpTNllAdvcpIQe77l+53e3CBoti53KWIeaNe0AV uR33V/xqt5i78jkGXLw5r7hKp87D8o3XXeTj2CX3c6eW5pbdE4O8M/DEhUuVcvJLyCue J/HxOYccIDOdOn0PgfLpjg1ooi2feDWeCRsPH41MC/6U3E11V3hs/g6YcluMAoJclkf0 RYrOLVM24b3kdzMeos5tsXRAFN9RPr1E5Ixv5qsOkkQyxTPZ6qhPRWOb4NWe8ELnZbqq Cz7MO6TMue7XovkrPAocu+1P2xG1vLWIb0lKRAT9tTf8MVYN0fsM1/hYKglqWz5WgZbA fArQ== 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:mime-version:content-transfer-encoding; bh=1IdhsUs/fdllTh2EJ+ScRqWrO1uX9GsPUvP6PugnTR0=; b=Ke5+qV1bwiABdoybUq98LRMZLo5pahd8OFYmVXETUnEQu3ItLvy2IOOPBDijdGmC/K JJN9461ZohaOpGQL3YdA18Jr4+kcINZqUJ0MSjYkSiH4qSTH8S38LI5GKXbWwfcDjXpU VCySwFatxeh5krODcSdoUBI8+F3CsYZIi7q4HHvUr28IPrfyv/DC7WsplfW0B9FtfBo5 cn3/vtef3eYjzns3HwDtCqOG5gtxiVaA/vGEJNkCxGWcjhYFAlSvLmZsTubraWIGAfB0 b9D7PMjiIx3rPbvPjyAg0MguptqCNnDJRSCPnY4BXLUyNMQpm4r29alieomUOO+xwUM7 a8dg== X-Gm-Message-State: APjAAAV24BispjBf8m9x4gMa/F937OMfg7sWx+BdmTBU9XBgllxFF6Ws WQIwnNYdO2tlWfdjkf4cekzaCA== X-Received: by 2002:a17:902:b94a:: with SMTP id h10mr91088007pls.265.1560481932763; Thu, 13 Jun 2019 20:12:12 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id e184sm1047863pfa.169.2019.06.13.20.12.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 20:12:12 -0700 (PDT) From: Viresh Kumar To: linux-arm-kernel@lists.infradead.org, Julien Thierry Cc: Viresh Kumar , stable@vger.kernel.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 07/45] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Fri, 14 Jun 2019 08:37:50 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 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.4: use existing scno & sc_nr definitions ] Signed-off-by: Viresh Kumar --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 1 + 2 files changed, 12 insertions(+) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 683c2875278f..2b30363a3a89 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -102,6 +102,17 @@ hint #20 .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 + #define USER(l, x...) \ 9999: x; \ .section __ex_table,"a"; \ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 4c5013b09dcb..e6aec982dea9 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -697,6 +697,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