From patchwork Fri Feb 12 05:14:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jian Cai X-Patchwork-Id: 12084747 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 A0C06C433E0 for ; Fri, 12 Feb 2021 05:16:36 +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 5822464DE0 for ; Fri, 12 Feb 2021 05:16:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5822464DE0 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:Mime-Version:Message-Id:Date:Reply-To: To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=7TFLG0MhbxtUVZX8j+qlaHhZhZeissi4efVHNv9eR1Q=; b=AfCQ/1AK/EfDA+dfFb42QRoPiC 5iG75zugt2cHyXJLEGz88icWYzkiEhBJ9G9sGHKNn8kru72SgoiIe5mVDsUMLbRSp/vQFkoSGKJwK YeS7cITQHdZ+47N4APDjYtOs8jefhH8wMUpCot07AQnlLA448ehEa18qtB2GVZkZtBpIWBSdi/yoK aEeG7rfDEUfAF1dpc0e9OOgh3J2oLsOjeNU+bMbL2iSlXZ5zVg3HLE8KK3D5MnSqmk3ms/vJGGMYU /ro2xaNoAZhCl4cOyFT6dqPEwHGpe6jjP+LO2C69NSNUwBv6CS+0a3wIzBN3XUxnd7XYXIgTy0E9W oydXwgZg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAQnP-0004TG-Sn; Fri, 12 Feb 2021 05:15:11 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAQnM-0004SX-Ha for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 05:15:09 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id f3so8012068ybg.15 for ; Thu, 11 Feb 2021 21:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:cc; bh=UsZfh0ugYXVBA8yeF7pE4YFwStzOHtAmek3RdORCX+E=; b=SzJL9vBy8lVTuUNig36qJ5I3eO9VZPL2gttToIRg/rfH0Rl+BdC92sD5+F5r7Z6XPS 7Arqpz65uTK4op7fIZV5M2CrdBGfXqaaSosq+n10YCqivOICp0yUQP6hdB54n5fIw7pe 1Hy+SVqmSBOeUvK4ugcpZHP+89/UvS+cxYhlmLMrNoANYkOwoaGuR7krjBoK7NZjq9zz x0LXWTU0Pq/Ri79FmStfQL4v28EPwr9qbwOD25x6W+CKPf7BwpB6AO8NceInXPHtwGQf lO/RywqfNIpjw86uTffqIHFIHPBUUsSTfvDx7CbnUSXaJ1drDsn1R+To1Mti4LY1JG6W rwNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :cc; bh=UsZfh0ugYXVBA8yeF7pE4YFwStzOHtAmek3RdORCX+E=; b=fA7TIGRm2WhNh93aFsQJAU8yyqkplJHVLnEdH1P1laDPaWh06NTb62KGDRGs7rcPpd hnqmH5Nhw1p0FmIk+pwzXo+MRfQDwOXd8zQRzrFl8K5Dj844E5+2vSwFE3RgBhMw7ICy XEjSDnSpQ8E1YPh0ybanMajJmRpNPxpvMFczANT1NPO1GQw0qbLTVOrGUfHmOnEwK7eT n2s3AlHkr4lWjYVHa/SPyY3GtOE51svFE7WwDFW8GwWhVwJNyb3IYws9yP+OVkyFaJNN qQwuWFCXSJD9vTHMl7amhU49Mk7B5EkrZkG00m8YpqMsfF2nNHBispv24jpAGJiYLT0r r24Q== X-Gm-Message-State: AOAM533fPSRASaoCOBwyI6nfpMY6e0LmD381TMSrBlrC0zdJ2mlOkH3b M0Ua8J5+l29ICHOw7e5K/p6SUXkWfcE+ X-Google-Smtp-Source: ABdhPJycIY3mywfzpize22XFsRLYY7NYl3ks6OFPoxSO3RoiL0EL5Ir2jRncglUNKqPUXzz6G9tAhg3k4Nay X-Received: from jiancai.svl.corp.google.com ([2620:15c:2ce:0:9923:3694:46ec:d62]) (user=jiancai job=sendgmr) by 2002:a25:ce51:: with SMTP id x78mr1842451ybe.198.1613106904807; Thu, 11 Feb 2021 21:15:04 -0800 (PST) Date: Thu, 11 Feb 2021 21:14:58 -0800 Message-Id: <20210212051500.943179-1-jiancai@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH] 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_001508_638108_2519EB19 X-CRM114-Status: GOOD ( 12.39 ) 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 , Daniel Palmer , ndesaulniers@google.com, Russell King , Jian Cai , Nathan Chancellor , clang-built-linux@googlegroups.com, linux-security-module@vger.kernel.org, manojgupta@google.com, =?utf-8?q?Andreas_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 a config CONFIG_HARDEN_SLS_ALL that can be used to turn on -mharden-sls=all, which mitigates the straight-line speculation vulnerability, or more commonly known as Spectre, Meldown. 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 Link: https://crbug.com/1171521 Suggested-by: Manoj Gupta Signed-off-by: Jian Cai --- arch/arm/Makefile | 4 ++++ arch/arm64/Makefile | 5 +++++ security/Kconfig.hardening | 11 +++++++++++ 3 files changed, 20 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..8fd0ccd87eca 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -34,6 +34,11 @@ $(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..d83c406c81a3 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -121,6 +121,17 @@ choice endchoice + +config CC_HAS_HARDEN_SLS_ALL + def_bool $(cc-option,-mharden-sls=all) + + config HARDEN_SLS_ALL + bool "enable SLS vulnerability hardening" + depends on CC_HAS_HARDEN_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