From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MISSING_HEADERS, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E37CC433DB for ; Fri, 5 Mar 2021 00:55:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A119764FD3 for ; Fri, 5 Mar 2021 00:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A119764FD3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MsqAvLgQyvgwFtoPqSJxNBLArRIV1k+JRUXHwctC8CA=; b=jSwk1cApR3XL5sIMvQEw+Jx8m Fw/ENM6VHu6QwUw5Fyqet0pm4k5QTJM4vGHWpwvSLf+mCY6DSm+ozRWlfyIg5JlVtdyWg+WT2ePSs ibZNm1hgPza9bg16+znMKBlr/a0WcLcTzzUsSoM+NHD6xcwh+Alc+jxLBzhNJ1YkyE2FlV1nfxwDx QkaNEj2U70Aij2nlRUNud4BmYgIx4aAWwGOogs9uk//YvhUHPT5Abqra+2G0KZxn0JDVjJHbum1s4 aUrLomZTxqT5P21fLtYJLJkylZ3bxS6j8XwyGYcayfhukSef5em6KupmziEKDLVB9m2al92Vce2pF 3J2NZJmgA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHyio-00B7b2-W1; Fri, 05 Mar 2021 00:53:39 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHyik-00B7Xq-N6 for linux-arm-kernel@lists.infradead.org; Fri, 05 Mar 2021 00:53:36 +0000 Received: by mail-yb1-xb49.google.com with SMTP id a186so646564ybg.1 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=VWCNrHGvDbhFFghgHXbfrUxzvSJwYIonz1RPhfUIx8w6nscEthuBswZyY+NHTIo5oe zVcEsGushKqLgR01P6HYcUks4SfRl8CkdQdFIsarH9Oo0dsP85zbsSck8zdmnSQ67dFh Hnf28VCHMFLkr3nmw/99NCalLc579Z9gR4dN2iXwcYr3IQuh/yQh4hNby69xccpQiQ19 1QCS+iJU6+cn0VLFSBKaF2N/VSQXMve60zJh81S4d0KmKzCs6F/N4FN086JTh5ZcIqOS v9/tX01kB5pcGRZsfBIacTgEMvk6d28Q+8TzFQMGvV0JukbolggzxdFkvlKpr9rBVovV krfw== X-Gm-Message-State: AOAM532/T9un/DMKsEXT7PiKP88WVm0QBbdom5euEEJgvSYddRSm3AUC DaY1EnNoDpDHYYPunfnazZvzhDvHqSmK X-Google-Smtp-Source: ABdhPJzNifQecS1ELfAGb8xMfod28CcY5fmiWPIkutWHFymb9agAnhUArzpzU6/YksGQ0r5lKWYUKmIrz7kj 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210305_005334_868536_B52CD077 X-CRM114-Status: GOOD ( 18.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel