Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2692443pxb; Thu, 11 Feb 2021 21:16:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwi0wQwBEc0MjaLhjBxPHN7wVfjRu9/9p86EbOdjyPD2NBwuWY1KPLBMxG57aYsXh+TgBB7 X-Received: by 2002:a17:906:c318:: with SMTP id s24mr1264290ejz.187.1613107000253; Thu, 11 Feb 2021 21:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613107000; cv=none; d=google.com; s=arc-20160816; b=ndZTAItDYbNt4BIUKuWxGmkZ/vyyQ1m1gMudDgdEI5jc06IOnrGuLp/TZOa0BOhLiP aXk8YtvyKW4c1Uqsw9p5YMribdoDGG+ewTfR/LI6UtwsSnvxBtkHZTLL3DPs9tSx2tz5 0KAbIpkhbVHR8EQAW6x8Dm0kxyZPDTygXpjBC+JBrJx8L0At3889vt7O9Jk8IGIGQCbw usuOe7lz13osZXlmtU4wkt5eGHCERjpdu/QDy2IhWAgTdPR22nIuuIP5QFl9a5MOktbw ZFRg8S8HQPVPJzgHU3vtMaY/can5ONGXV9H/GvoGmJK/l6N39mdJGl0M6uCLe/421lIS SHuw== 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:mime-version:message-id:date :sender:dkim-signature; bh=UsZfh0ugYXVBA8yeF7pE4YFwStzOHtAmek3RdORCX+E=; b=wjK24x/R7xscf0uTN3JvaFkK1Zeu+UYY3b7kwR8v5A4ZiIeYGomT2oGm2WjX/Fr5Ss 1N73lflLGnDdoFJJ677VDMsFuyEYeLyQJBv6A4h7GsxS8Y29agZO3y4Z73N7Hy3KiIWr sXCOvxukVRPlNOvqdTcHce/81sssFWQd845V0Yb6pkKjKEpgn2ShysisWW/3Pc1Dou2J FIQFsx+0nCqGICu9A2+e6ZGeJ33JoVC3dA0pE68AmV2Iy5jBJ8lYcZK4qUO9sbr3IBOw /11x320FXYy7L3M0xkb9FC8qyZP4L2tWq/oyItcJ/+UGY/h2pBiNQYNjPV1wefzJcash //6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SzJL9vBy; 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 bi1si1222328edb.247.2021.02.11.21.16.16; Thu, 11 Feb 2021 21:16:40 -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=SzJL9vBy; 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 S229457AbhBLFPv (ORCPT + 99 others); Fri, 12 Feb 2021 00:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbhBLFPq (ORCPT ); Fri, 12 Feb 2021 00:15:46 -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 BEABEC061574 for ; Thu, 11 Feb 2021 21:15:05 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id f127so8558934ybf.12 for ; Thu, 11 Feb 2021 21:15:05 -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=ibnQyCqc7T7F42uMt/dYxT/RM9WXweU21uONUfo3NStSOx6LLDPmHdR8IOGtqHcarZ drQvxxehi84gdXTP/HF6petYm/zGtOzPrF4f8BjaTX1sxxd+kFXOApKnOqu12KVpa2MQ qychjDmHHSq5F37WnP31njCWByFA2tZU4YhJShDa/o7ePH5ABCG0aO5Alxm+FG/BZmpN LIRmemJibmn323ErRfawbA7NgB2dD1L6doGToG4iCd+2TfHLV6ACfavTsN1fNZUmmswx dB7mvfLk1kfx9UN5mB3Vtas+SI4QTRyAAWtsSFYELYtwmoo4WGw37k2EJ8b36Tzfcv5b siNw== X-Gm-Message-State: AOAM531SZ3Y1VMdiRKuATZt1+UDCb0Wyssxn1tnzMPTC318ncp6jdZyp Ceal48VLhAPH2sHWFMXQqtlqRgDYgjDv Sender: "jiancai via sendgmr" 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 Cc: ndesaulniers@google.com, manojgupta@google.com, llozano@google.com, clang-built-linux@googlegroups.com, Jian Cai , Russell King , Catalin Marinas , Will Deacon , James Morris , "Serge E. Hallyn" , Nathan Chancellor , Arnd Bergmann , Masahiro Yamada , Kees Cook , Ard Biesheuvel , Daniel Palmer , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , 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 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 -- 2.30.0.478.g8a0d178c01-goog