From patchwork Fri Jul 12 05:27:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168865 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp394465ilk; Thu, 11 Jul 2019 22:29:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1kbK23BegyAVwiVgtFi2gzC2ZSIUI/spF9iHK6pzO7aKlntNYLB/GSVYmxI0WSF28FU2J X-Received: by 2002:a63:e953:: with SMTP id q19mr8673398pgj.313.1562909357626; Thu, 11 Jul 2019 22:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562909357; cv=none; d=google.com; s=arc-20160816; b=DM0lEmj6Jk1PZ6NjeuYkO+3m6vxvjpKBWcIk3X5uv3khShDAV8Ut+7yASJDBCvHwzC /ofQq2IyF5GHjfnLsg4EhAa4G1DC1pQMr9+MRU44AY00oOSvtnBRfk+ETv+/pqB350iZ re8ezwU7QlpRDoExhZcPddJUN8001q1XbQyElYr3jWSAL6TJ6JYTW8sFweDCwoVhVREi lvIHvweepA4gZzPzNR4F3h8hdv8vPqzNzmHPxEYlFSi7nhTzOVH2fxgar7RE6GW6QSOi Y1ppvX+GqNDlDhcU/zdBoa/7tSsr4XLckNXsgZ+BuDXCL003A7ugZnJS/f9R9IqAWRYj p1+w== 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=kj+NV5Qc06d6qpJY3MBqQkJFwuyx/6G6EcZmM4sA+YliDrtxs1MN25cpbkgM11ixBG qHZgQcR7aIpmXvR5LVQPcM55u/F1m/EeI66RuzkROU3TWY8b9CchM3HcHvYHx8oZJ1l6 YXUKxdSS4G4+eZU3/F9Kpcgy5y41CtfdOrYlHRuK1/qIykIh57injejhrne6wUosjwUD 0CXQxFusqsP/R+FmmOxyHK4uZGG/Kcgbxdwa8roUWzIObRhlOCcqVlr0jpkERZdMispW UZN0/Sz9M0RSfmBMzc5ZshM49CDfDFuX+QcSKEShiyYghOtGF8DZsyIqn8vhxlsxB/Ox YP5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NLbMjzAl; 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 e36si5303191pgm.17.2019.07.11.22.29.17; Thu, 11 Jul 2019 22:29:17 -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=NLbMjzAl; 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 S1726033AbfGLF3R (ORCPT + 13 others); Fri, 12 Jul 2019 01:29:17 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41516 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbfGLF3Q (ORCPT ); Fri, 12 Jul 2019 01:29:16 -0400 Received: by mail-pf1-f195.google.com with SMTP id m30so3786611pff.8 for ; Thu, 11 Jul 2019 22:29:16 -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=NLbMjzAlqCBkT5p9dJVqb2Z5dGhi0jH/DelTojWG0Hk2jdOfuiefznDfWJuowL/Agl 9aokXDeJ+NvIotQEG7M9THxjw+tb4VCdkLg0zn5oOVf7UqOFxPmQNucZL3G6T4d34qB7 t4PnLhRDb1YvAtUJ64bQ3QYulrevKjRsE8L0fyxvWH95xDWSk9+Xh76mvSBfdlZUq6lQ XvmcFSoFmIX3B4BQMIZGp1/ew1VgB/sqXv79EloYkvfP3rnZvDNjRXbvP1Z+zMig52iB Dlq9x9DLYRFCXW8bKyADSSuKd2qCmMDKgLmgOmKouq+eU0jfATvKGuL0UJyP3z0HwRZu sM9w== 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=aVIOjgoCUVqCuOM+QhnEbFIfljTPoukFgFJBKDHRTDraR0EA8fG97XYLSre5a5/583 +L9CIzRFZCL+gRYFNQAaU8cErjXVcMooJsCc0mT5zFWZAhnSKHSHLg4HRVIP7r6zLbi7 cudPkw4dR6r+/cEjgbExdmMArihWcCUwBdhjVNjeZnKjHjO4nN45gh/uve6H+bDowcOx IdshdSQDKhXVwJF3up14s7Ob2R9N1wOzx/RMd8s/PC24cGdYcVSpkSSh1XExcx14eRMi Z+reOuCS+AYXpq0X3RHu5U+ThdZ+koY7xJDj9sJYwHlZp1RyjNfEyEY/i3CcZWdZ4WIi ToSw== X-Gm-Message-State: APjAAAVGCC//rsxytspA044y0+zaN7C1F/BU20zab3/g3DpKN2vxpG7y rzQLO6wbh8U+Y/NXLUuJLVoK1Uus1/A= X-Received: by 2002:a17:90a:a116:: with SMTP id s22mr9286580pjp.47.1562909355740; Thu, 11 Jul 2019 22:29:15 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id d23sm5914809pjv.18.2019.07.11.22.29.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 22:29:15 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 V2 06/43] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Fri, 12 Jul 2019 10:57:54 +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