Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1635215pxb; Thu, 4 Mar 2021 17:05:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzx+mRyB/KoYM+j7lLQetsMEtbhkz2260md/YVSiSU32PH/ublBei2nmyExdGXSpKcZSqu X-Received: by 2002:a05:6e02:b2c:: with SMTP id e12mr6196355ilu.143.1614906339862; Thu, 04 Mar 2021 17:05:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614906339; cv=none; d=google.com; s=arc-20160816; b=vUa9OxB02BIzpWCBFiOQl6knc4Zb5hBDQv88Vz2aCDPa3W8+LiwkYiZzzSFLl+qybn Ztej/6VkCYKy+XtbKjVaoeeBZN+XoASJW3bQ21BxQwYeAcllkHn21prlmMRjPPIr81mo EchXEC2ewgLLPLJQfM7/jLqEKjlBQJROt/l/k9butUJZeOnNMCReIAlUIDPQyBeHfap2 Vj6HMEdHj/MYL6uInj3hCp+kRiOd8ybRvejMBmtXuS94Wq9poeSP5/J0p9yXnhOvripA a7q9Z3NEryAte4DTEbSYtGb5kQ6rgPZrdDvVDtrprV7kjQm+gC8VEJGY5wchPYClWSQm Oy3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=s0a03NeiimEs02gcpf/77HytMIb3TLvi/V8gs4T53vU=; b=EmDm2mtZ79ZMQ8M8+azToJqekzuTQB+GldE04sBriYVH3FkBnbY6jEesiXM1Q+F2Wt zx02NEq7SHvO7wIsgekXOQ15vfBpgqLyP2EEIQfXoqUyCIlm5vYDL+fie0qd1qbykMCE tbiSqb/YcQObVUmKjT5Qv8QUJwKMUhgejjQwZtzYL8WO5uQDBBwxXUCRqb8JKEH3qc4m 4LIAk0xxOmiPa/r3DF48PeUl5gXBxrOlwjygzFGzUJaD2CIDbAvF5UwUzCUcCIXOm2s7 okLzgvh4KMqhR27UrO0dbAGz8bgFUvW9uridAmHTM/4b1JHjbXnh6+uRojDYvdl+J2c7 QkpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lUvKcrAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si759607ilu.32.2021.03.04.17.05.26; Thu, 04 Mar 2021 17:05:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lUvKcrAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbhCEAxc (ORCPT + 99 others); Thu, 4 Mar 2021 19:53:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbhCEAxb (ORCPT ); Thu, 4 Mar 2021 19:53:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9644C061756 for ; Thu, 4 Mar 2021 16:53:31 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q77so642620ybq.0 for ; Thu, 04 Mar 2021 16:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:cc; bh=s0a03NeiimEs02gcpf/77HytMIb3TLvi/V8gs4T53vU=; b=lUvKcrArmDzU4hhIn19yXnWghv4IeaePzhyeh1iVUFnn/5/6O2BI7BsDD1MHKJyRs2 RAyPCJER4zhqlgnJg79GENfvVkc3l7EIrWxnr8ZLsAopDB1IaGqDAtZH10NJTQdm3nrW 2gleXvBpVAgSlTZpvZGXP7IGzILkvt8qlYMV56Vqooc0W03LZrnCDWlJq/gw1aDBT6NC 8fE2L8E3/ExcgFRNXzNgiMsd8IN7+eFhZ5OtXFE2nljCmJsSPSbmyspdd7xUb81P7RFt AXVjG6GTxA71nZEbGSKt0V9FTkLssNeeHm9mcd9LZsE/8yUEe5AUPCwgSTSSxZHsKhX+ VQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=s0a03NeiimEs02gcpf/77HytMIb3TLvi/V8gs4T53vU=; b=LR+8rFCynv31SvN2XTcWhR319MTuFTaFXHbGKRefYXGrbYkgUNLgQh26218vmkyqxQ 3+52mNDuwJeO8GfMilBAUjDQ/98tmSMCLW4hS9zKJFJtl6vMoaO0JYLO9ArDaa0oE+C5 muZ3vAGzOtClSrzKxOTrOzFfVFeHs5Fh3mqgMScxD+C1NKdO9MP2zK/g0FwOXprec9kv 3kS4Xb9AA6zrPW1vUaub/pQVzyHLxNl/Cyjlz0UpY7xqj3vIhKfQ1UTjgsR3UYY13ygG hsJ2rnJCA1x2U/YO17rfBcxMp5QIOMltgntakoujqOP/ltHTSHnA+YgpMb8nFCyxJspX Wl3g== X-Gm-Message-State: AOAM531I5d/1F2Eigcbt92+RnRjyUpADx/B/3FqjMw3pXBFCYni2EKw6 cWPw4F/zZTmrcN29qzK1rHJEaOUS5ywS Sender: "jiancai via sendgmr" X-Received: from jiancai.svl.corp.google.com ([2620:15c:2ce:0:1164:dbaf:a707:265d]) (user=jiancai job=sendgmr) by 2002:a25:d8d1:: with SMTP id p200mr10331970ybg.14.1614905610829; Thu, 04 Mar 2021 16:53:30 -0800 (PST) Date: Thu, 4 Mar 2021 16:53:18 -0800 In-Reply-To: <20210223023542.2287529-1-jiancai@google.com> Message-Id: <20210305005327.405365-1-jiancai@google.com> Mime-Version: 1.0 References: <20210223023542.2287529-1-jiancai@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v6] ARM: Implement SLS mitigation From: Jian Cai Cc: ndesaulniers@google.com, manojgupta@google.com, llozano@google.com, clang-built-linux@googlegroups.com, Jian Cai , Nathan Chancellor , David Laight , Will Deacon , Russell King , Linus Walleij , Russell King , Catalin Marinas , James Morris , "Serge E. Hallyn" , Arnd Bergmann , Masahiro Yamada , Kees Cook , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Daniel Palmer , Ard Biesheuvel , Ingo Molnar , Vladimir Murzin , Marc Zyngier , Andrew Morton , Mike Rapoport , "=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=" , Mark Rutland , David Brazdil , Joey Gouly , James Morse , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds CONFIG_HARDEN_SLS_ALL that can be used to turn on -mharden-sls=all, which mitigates the straight-line speculation vulnerability, speculative execution of the instruction following some unconditional jumps. Notice -mharden-sls= has other options as below, and this config turns on the strongest option. all: enable all mitigations against Straight Line Speculation that are implemented. none: disable all mitigations against Straight Line Speculation. retbr: enable the mitigation against Straight Line Speculation for RET and BR instructions. blr: enable the mitigation against Straight Line Speculation for BLR instructions. Links: https://reviews.llvm.org/D93221 https://reviews.llvm.org/D81404 https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerability/downloads/straight-line-speculation https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerability/frequently-asked-questions#SLS2 Suggested-by: Manoj Gupta Suggested-by: Nick Desaulniers Suggested-by: Nathan Chancellor Suggested-by: David Laight Suggested-by: Will Deacon Suggested-by: Russell King Suggested-by: Linus Walleij Signed-off-by: Jian Cai --- Changes v1 -> v2: Update the description and patch based on Nathan and David's comments. Changes v2 -> v3: Modify linker scripts as Nick suggested to address boot failure (verified with qemu). Added more details in Kconfig.hardening description. Disable the config by default. Changes v3 -> v4: Address Nathan's comment and replace def_bool with depends on in HARDEN_SLS_ALL. Changes v4 -> v5: Removed "default n" and made the description target indepdent in Kconfig.hardening. Changes v5 -> v6: Add select HARDEN_SLS_ALL under config HARDEN_BRANCH_PREDICTOR. This turns on HARDEN_SLS_ALL by default where applicable. arch/arm/Makefile | 4 ++++ arch/arm/include/asm/vmlinux.lds.h | 4 ++++ arch/arm/kernel/vmlinux.lds.S | 1 + arch/arm/mm/Kconfig | 1 + arch/arm64/Makefile | 4 ++++ arch/arm64/kernel/vmlinux.lds.S | 5 +++++ security/Kconfig.hardening | 8 ++++++++ 7 files changed, 27 insertions(+) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index dad5502ecc28..54f9b5ff9682 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -48,6 +48,10 @@ CHECKFLAGS += -D__ARMEL__ KBUILD_LDFLAGS += -EL endif +ifeq ($(CONFIG_HARDEN_SLS_ALL), y) +KBUILD_CFLAGS += -mharden-sls=all +endif + # # The Scalar Replacement of Aggregates (SRA) optimization pass in GCC 4.9 and # later may result in code being generated that handles signed short and signed diff --git a/arch/arm/include/asm/vmlinux.lds.h b/arch/arm/include/asm/vmlinux.lds.h index 4a91428c324d..c7f9717511ca 100644 --- a/arch/arm/include/asm/vmlinux.lds.h +++ b/arch/arm/include/asm/vmlinux.lds.h @@ -145,3 +145,7 @@ __edtcm_data = .; \ } \ . = __dtcm_start + SIZEOF(.data_dtcm); + +#define SLS_TEXT \ + ALIGN_FUNCTION(); \ + *(.text.__llvm_slsblr_thunk_*) diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index f7f4620d59c3..e71f2bc97bae 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -63,6 +63,7 @@ SECTIONS .text : { /* Real text segment */ _stext = .; /* Text and read-only data */ ARM_TEXT + SLS_TEXT } #ifdef CONFIG_DEBUG_ALIGN_RODATA diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig index 35f43d0aa056..bdb63e7b1bec 100644 --- a/arch/arm/mm/Kconfig +++ b/arch/arm/mm/Kconfig @@ -837,6 +837,7 @@ config HARDEN_BRANCH_PREDICTOR bool "Harden the branch predictor against aliasing attacks" if EXPERT depends on CPU_SPECTRE default y + select HARDEN_SLS_ALL help Speculation attacks against some high-performance processors rely on being able to manipulate the branch predictor for a victim diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 5b84aec31ed3..e233bfbdb1c2 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -34,6 +34,10 @@ $(warning LSE atomics not supported by binutils) endif endif +ifeq ($(CONFIG_HARDEN_SLS_ALL), y) +KBUILD_CFLAGS += -mharden-sls=all +endif + cc_has_k_constraint := $(call try-run,echo \ 'int main(void) { \ asm volatile("and w0, w0, %w0" :: "K" (4294967295)); \ diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 7eea7888bb02..d5c892605862 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -103,6 +103,10 @@ jiffies = jiffies_64; #define TRAMP_TEXT #endif +#define SLS_TEXT \ + ALIGN_FUNCTION(); \ + *(.text.__llvm_slsblr_thunk_*) + /* * The size of the PE/COFF section that covers the kernel image, which * runs from _stext to _edata, must be a round multiple of the PE/COFF @@ -154,6 +158,7 @@ SECTIONS HIBERNATE_TEXT TRAMP_TEXT *(.fixup) + SLS_TEXT *(.gnu.warning) . = ALIGN(16); *(.got) /* Global offset table */ diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 269967c4fc1b..db76ad732c14 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -121,6 +121,14 @@ choice endchoice +config HARDEN_SLS_ALL + bool "enable SLS vulnerability hardening" + depends on $(cc-option,-mharden-sls=all) + help + Enables straight-line speculation vulnerability hardening. This inserts + speculation barrier instruction sequences after certain unconditional jumps + to prevent speculative execution past those barriers. + config GCC_PLUGIN_STRUCTLEAK_VERBOSE bool "Report forcefully initialized variables" depends on GCC_PLUGIN_STRUCTLEAK -- 2.30.1.766.gb4fecdf3b7-goog