From patchwork Fri Feb 12 19:52:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jian Cai X-Patchwork-Id: 12085989 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=-16.3 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 39A38C433DB for ; Fri, 12 Feb 2021 19:54:32 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 E9B4864E2B for ; Fri, 12 Feb 2021 19:54:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9B4864E2B 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=E+nNI+lvBNx5nZiGzgNmcnaHTK9jeMFJVNaSSgEFtH0=; b=UrLSbDMyPNiQbCCUthm8/IvfL wv+26gWzo2ViIplPF2W8yPIE5JxZeGrhGCB3PucK4YTy90a72mmuDZJFQKO1F4rWfgC6XyBvKN81j Whd0fNTxmJ4lSUeugjUHN7cqi5EIm+TcgY4gj4Vm5lrVONsU7t7rO1qj8o1UwsjAnT6q4pzYyo/rE 0dtfl65K6oCoosDrrn4MUPKcsaVIW+UB84HP9Imbv+tLn4W0r6VV79o7BUZMfPJbxpgkYp3GEMxqU dDb/AdL73TYxtTAyzVlN2+bEXPsGrMayTalJVK3eZYqzIbqG2+266753IFuLm+2HVFY0eOuXY2mtp EWZoCAWVA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAeV0-0004iE-JV; Fri, 12 Feb 2021 19:53:06 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAeUx-0004hQ-JW for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 19:53:05 +0000 Received: by mail-pf1-x44a.google.com with SMTP id j7so347561pfa.14 for ; Fri, 12 Feb 2021 11:53:01 -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=i9bXYkYkNrS/myxp10YTd6xQPzarqSevtONWXeGJPlg=; b=CEPFGAAZTn1YBSHByUfgpcddUlDuB43hOXZpOdPUc+0zn3cxDCWnpYIBMPOElNPPLW cIPJ2hF4x195i6fCSs1CWIpOMlYYJx0hpXRU4Y1ennrFKXBMgYS/5gSl11abA8hXM3Uj WvhElyaTAr+5YhBuMjzBs5fMk+8yHPmuKFDhw7ZoQ0GrBmRAI5pj7oW8bwI6ARh0Kn1/ v5VwKf+p3vFo+qcUs9UykjlqnA56+Ki4Oczm93zCXA2zfa7ovKXRoJjTaAWyyLCs75x8 2ZgJ7qMogVu4vu8BBfJUCJ7YD/G5dEJuhNLufGQQAyJG/8STZNwx0DCPBUl+WixZl4le yh4A== 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=i9bXYkYkNrS/myxp10YTd6xQPzarqSevtONWXeGJPlg=; b=U/7Qlq5aoJph52oeHwBX1TDctJgTVEZT9Jhdd8dCt/e0HpsOdeqjW4+y+BuvhhshbU h0NlYPMG/2UHnkOHgOi3ZhO0CJTYFS6dT+YU5o3tQTu8jkQLdHiWje04uPaON3vsuQpi gYLf9sWS4/U/e52mSTWJGOx7nCpVQqrQc4SgBVwd1b292OCxwVgvYlPXBzOO7SUm3j6i spLxby9WLZj4a6/gPH7Vkdhi1PSKOyoBWj9bBL4cBjo/ZEN2XfBCP+sLx1rKbV/gSY05 VkTgWSffgunPUfPl5ltZxLYhyhBqNaBolKRMtO+PMaRQaRm6IBaaI/gj91WA3dWuojGf ujpA== X-Gm-Message-State: AOAM533ua7YrUmXIR0Z4hQ8Xh9+TDwsc8auaTV3HMQ/PmuNdiwIN0bqm Aj7hiZeRsj1c9pJNpGPudB3IDgaTzk/i X-Google-Smtp-Source: ABdhPJzcLNW+FrrZp7ZKnrKVr8H5UQftS7u7Nn5TK/9khzHO3nQj/KyeiMBomoDzHkeCk9/NPtm2JLlrp5NX X-Received: from jiancai.svl.corp.google.com ([2620:15c:2ce:0:8cad:e5dd:2b3c:2e84]) (user=jiancai job=sendgmr) by 2002:a62:3852:0:b029:1da:7238:1cb1 with SMTP id f79-20020a6238520000b02901da72381cb1mr4445517pfa.11.1613159579252; Fri, 12 Feb 2021 11:52:59 -0800 (PST) Date: Fri, 12 Feb 2021 11:52:53 -0800 In-Reply-To: <3f61af0eee9b495e8e8c032902d033c5@AcuMS.aculab.com> Message-Id: <20210212195255.1321544-1-jiancai@google.com> Mime-Version: 1.0 References: <3f61af0eee9b495e8e8c032902d033c5@AcuMS.aculab.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH v2] ARM: Implement Clang's SLS mitigation From: Jian Cai X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_145303_701042_C2AC0898 X-CRM114-Status: GOOD ( 12.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Kees Cook , Arnd Bergmann , Catalin Marinas , Masahiro Yamada , ndesaulniers@google.com, Russell King , Krzysztof Kozlowski , Jian Cai , Nathan Chancellor , clang-built-linux@googlegroups.com, linux-security-module@vger.kernel.org, David Laight , manojgupta@google.com, =?utf-8?q?An?= =?utf-8?q?dreas_F=C3=A4rber?= , llozano@google.com, James Morris , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, "Serge E. Hallyn" 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. Link: https://reviews.llvm.org/D93221 Link: https://reviews.llvm.org/D81404 Link: 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: Nathan Chancellor Suggested-by: David Laight Signed-off-by: Jian Cai --- Changes v1 -> v2: Update the description and patch based on Nathan and David's comments. arch/arm/Makefile | 4 ++++ arch/arm64/Makefile | 4 ++++ security/Kconfig.hardening | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 4aaec9599e8a..11d89ef32da9 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/arm64/Makefile b/arch/arm64/Makefile index 90309208bb28..ca7299b356a9 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/security/Kconfig.hardening b/security/Kconfig.hardening index 269967c4fc1b..9266d8d1f78f 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -121,6 +121,13 @@ choice endchoice +config HARDEN_SLS_ALL + bool "enable SLS vulnerability hardening" + def_bool $(cc-option,-mharden-sls=all) + help + Enables straight-line speculation vulnerability hardening + at highest level. + config GCC_PLUGIN_STRUCTLEAK_VERBOSE bool "Report forcefully initialized variables" depends on GCC_PLUGIN_STRUCTLEAK