From patchwork Thu Aug 29 11:33:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 172583 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2091116ily; Thu, 29 Aug 2019 04:35:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1wUo+SHTJx0qjyAd3dj1kQQJI4sNhCz4ZGRnUuiESTa1JcSbD0RZ1khdSDhchNe+hNgt+ X-Received: by 2002:a63:c006:: with SMTP id h6mr7843442pgg.290.1567078509784; Thu, 29 Aug 2019 04:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567078509; cv=none; d=google.com; s=arc-20160816; b=p5GHjEzAP49d72jDdhZCsg0vbRqfniOvLHHjcc22h0mTMFIKZnkxG8Qkm9b9i2XcQI t2ZpfAAXNPeqA+/9J1QgLxJupASglwSknPQ0RWoga6zVFvzk6eBdAaXKj1DQfdnOJlnj wyi+o3ci6ojD4QfQ0+OIOXZdrmPxWt/v+lIDnDFDp831KKN8/nHecRzO2immHoHe4HWb FjZV/HFmP7dAwVbb0aKJhl3v3ePuMaOx9X+ByRXwm3JOwiGnsxXRpJbou130eCYf5rZ9 C/DIDVS/cQPyPdamlJLl2t7F92HAEzNVyN9Xr2OG7WxjSpX8nlmKt6Q3o916FG/cT9HH HrsA== 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=oHRd3/EfCeviYLB6brxBSfvySFx8aiDPnX3xs/19AH+CHIrsS0nTvP9FHIp5cC6suw LZ+GMiVRK8beh792jHlGoqiJEPDCcs8wOb1LlTO7FsrkcPpDxz98K/k1G7klMswDE5/p KJcfllavOuRCfCNP581l8CeQutId0+kwej3X+h3uBwJvEAzYngvb1z3GU8Mfj5zlHRfY kQ+1kiam0zpfWUyhGiARVlJ2b6+AzHba4MQDY0CmJ7ufXKkUq+/TTrLKyyCVonAitfRs 2Q2kq2UDoE+8IzPmZlhPTjATskJXSVjv7isibO0lvcO8/HBntv0WMrQk2prNFW02Exqd JS+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nxI85Uwx; 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 i2si1752366pgk.534.2019.08.29.04.35.09; Thu, 29 Aug 2019 04:35:09 -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=nxI85Uwx; 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 S1727040AbfH2LfJ (ORCPT + 14 others); Thu, 29 Aug 2019 07:35:09 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37503 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725990AbfH2LfJ (ORCPT ); Thu, 29 Aug 2019 07:35:09 -0400 Received: by mail-pl1-f195.google.com with SMTP id bj8so1451884plb.4 for ; Thu, 29 Aug 2019 04:35:08 -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=nxI85UwxnbVBJqSbq8Ywtoc623bVciPB583W6cIvsNcR9oBenNkMhgmn56N8dl7tHE HCJXonvD30tGaKZHMMV+hUfBy0X963d3yoXUwEU4wjSg1Z72lbwKhxPibPpL4vvKT/sr d9eU0YSkgUUaRy9GZaJXXWZccVQd7hOExhRb4tLvsZBKRmh5CCx4FM+iAh/eQCsKLWWp FIY3VPxy1ObVuPcERjVujhSRX3z9hbu98dIF01oxC51utQfIXqj2ZtYwJ+WWA85tkvl2 4cF/61lyqS+8CzAr/GFd2AGhz0eitx64Llmj8Bs0pXoci4lMlRg6vnKzxGxcF7afafI0 OAOg== 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=nzc+bMDn9x0oy0k79dQnB2e+7k5RYgRK/wkhTjppKc/UwU/lqgkcb+SRezfJ22x7vr uw1hJjJncdBxOoj97r4to4wGntlFZZ6CilKoUQCMCDjJHhPAL3wII4JB3TRXeIeL8Ql+ mZjObrwi0jFJOdco2X2mJsMOfFHZeEq1QLomf/g4rRl4D/dYkrVe5uYkHJ5bYTTocLqC +mfq1xn2RLkmZtnp1JtsVNA9O4pZ8/jS5Q4CLH8uwKq1S/FgrsAOO9zRP/GJEEUlwSa7 8DYGqdO+WQwyNmDVO4RUkXQDXp91Ck5cnuAD9sip8pBiu3MUJ8E4d6BMx4bLPglR1lMT JyEg== X-Gm-Message-State: APjAAAUrP6HevA4j9SCavWoHoL8tND4J0OG5XzBPjCqwoLORfRiVoFpj P62KphGSA6/8ExGs8Rlub1NsT8bx+es= X-Received: by 2002:a17:902:f217:: with SMTP id gn23mr9333792plb.21.1567078508102; Thu, 29 Aug 2019 04:35:08 -0700 (PDT) Received: from localhost ([122.167.132.221]) by smtp.gmail.com with ESMTPSA id u18sm2794235pfl.29.2019.08.29.04.35.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 04:35:07 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry , Mark Rutland Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH ARM64 v4.4 V3 06/44] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 29 Aug 2019 17:03:51 +0530 Message-Id: <093a9777605bdd2ab2c33948a4e7a3fbb275de4d.1567077734.git.viresh.kumar@linaro.org> 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 Reviewed-by: Mark Rutland [v4.4 backport] 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