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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 23B43C2D0EF for ; Tue, 31 Mar 2020 19:46:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 F06F22080C for ; Tue, 31 Mar 2020 19:46:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gKuYDq2N"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eJAdqBJ2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F06F22080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-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=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yDcAxZPn4VDYqV0iXbIo9v6pFAabn9kQm0W0P9GCMpc=; b=gKuYDq2NdweO0W TMWLkUiZWcDEjEchB6UAfZ4ekDJorMujXIWdNf3ZRZv6Ax5GesfvBNm6TrNYM2SzeoYvVd7+NG+n2 Nki90ABaw/fXx8K7JjrE0WsHlZvMTYs8GhQy4svmRZCdyZe4XCAqTV9O8/Kb3Hto3XGmh43t2fuPE h9Sgs5mcu3Ig/63zExJvdGy6BVFVvH2C86Nm8oH3n8IJ29ArTLz3O463xmXULme7FIO7W0dii8pUh u5xi8Wl/bgFt7c/WvQwk+NO/R76pDI4Q3pIYwtIYN8tSLf9o+NlYE1r+PwQ9wxl+aeEHgbGdyjcE3 rYGHoLpYzK1YnUO1Sprw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJMqM-0002XW-Lv; Tue, 31 Mar 2020 19:46:38 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJMqK-0002XC-Bp for linux-arm-kernel@lists.infradead.org; Tue, 31 Mar 2020 19:46:37 +0000 Received: by mail-pg1-x544.google.com with SMTP id h8so10835548pgs.9 for ; Tue, 31 Mar 2020 12:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=McSfVGO53GT+onuty+si9A0D5AuT8lLRpPmZo3ttlOM=; b=eJAdqBJ2z+laXu2VLjBHH8VchzOd8EZdFs0BxtKQ4C/pCCkyIaYKGwn7nAtZ5zWCEd qAbDjfQh+SpNHwv6Oq2Dn4fxkbDnWRQgrkCbMgwp3KnFALPY9vpzQuEcHdt6FE8y5LER qwR8Hi1L0wq8QOAr2CPpwFg2W+GOyXG+PA7mI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=McSfVGO53GT+onuty+si9A0D5AuT8lLRpPmZo3ttlOM=; b=ZT35jateITF1WB1NU7Bq6/e3vcjfGSDB/MwwGAQd+PeQbEbdfYr2eXwKU5SV3I7uyC PiXQnsWEBM/YBd7u4fPMZ0m59cwSqnLyy+ydxl8HH/sZqq4+c/wd+zUSjFZauQkUVy7W yo36cL1S1dBeeIJxH4L/dYw5Dw2QtVts2zMqzAMcbiC5vHq1SraTvfiU25AVUOPJR50a 6fkPGoA1FgUP/X0jwWsaCjy6Tkmw3W3OnhHsVvebsJvMv/a+jtx3MHp2XJXxNgyhGu6J QfHT0tDlddtOa5yPirM2KXkkSLYJGUspXbTXL8PJ/F4qPNdBXbGd98ZgwYfw9Jx03GXT slZQ== X-Gm-Message-State: ANhLgQ0Lxzi+ZJYiXbQPmXER5sVlD3TdqiVEgs0G7ISdQUSV2qPRPQoh xzKSE0+MzXuaHjdxZu9ExP2HJg== X-Google-Smtp-Source: ADFU+vv50aemtn2DxG4hvoaoGIYJraig6CnwiJgc4tMf4NsQFH4BpYFhb/jSce3yhJjyu+iPKsJ3Bw== X-Received: by 2002:a63:3187:: with SMTP id x129mr18660713pgx.180.1585683995603; Tue, 31 Mar 2020 12:46:35 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o65sm13181259pfg.187.2020.03.31.12.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 12:46:34 -0700 (PDT) Date: Tue, 31 Mar 2020 12:46:33 -0700 From: Kees Cook To: Mark Brown Subject: Re: [PATCH] arm64: Always force a branch protection mode when the compiler has one Message-ID: <202003311246.3BAE76AF1@keescook> References: <20200331194459.54740-1-broonie@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200331194459.54740-1-broonie@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200331_124636_422905_19A962AA X-CRM114-Status: GOOD ( 19.53 ) 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: Mark Rutland , Szabolcs Nagy , Catalin Marinas , stable@vger.kernel.org, Amit Daniel Kachhap , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 31, 2020 at 08:44:59PM +0100, Mark Brown wrote: > Compilers with branch protection support can be configured to enable it by > default, it is likely that distributions will do this as part of deploying > branch protection system wide. As well as the slight overhead from having > some extra NOPs for unused branch protection features this can cause more > serious problems when the kernel is providing pointer authentication to > userspace but not built for pointer authentication itself. In that case our > switching of keys for userspace can affect the kernel unexpectedly, causing > pointer authentication instructions in the kernel to corrupt addresses. > > To ensure that we get consistent and reliable behaviour always explicitly > initialise the branch protection mode, ensuring that the kernel is built > the same way regardless of the compiler defaults. > > Fixes: 7503197562567 (arm64: add basic pointer authentication support) > Reported-by: Szabolcs Nagy > Signed-off-by: Mark Brown Reviewed-by: Kees Cook -Kees > Cc: stable@vger.kernel.org > --- > arch/arm64/Kconfig | 4 ++++ > arch/arm64/Makefile | 7 ++++++- > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index d3efdc095a17..1e46746e8392 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -1537,6 +1537,10 @@ config ARM64_PTR_AUTH > This feature works with FUNCTION_GRAPH_TRACER option only if > DYNAMIC_FTRACE_WITH_REGS is enabled. > > +config CC_HAS_BRANCH_PROT_NONE > + # GCC 9 or later, clang 8 or later > + def_bool $(cc-option,-mbranch-protection=none) > + > config CC_HAS_BRANCH_PROT_PAC_RET > # GCC 9 or later, clang 8 or later > def_bool $(cc-option,-mbranch-protection=pac-ret+leaf) > diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile > index f15f92ba53e6..370fca6663c8 100644 > --- a/arch/arm64/Makefile > +++ b/arch/arm64/Makefile > @@ -65,6 +65,10 @@ stack_protector_prepare: prepare0 > include/generated/asm-offsets.h)) > endif > > +# Ensure that if the compiler supports branch protection we default it > +# off, this will be overridden if we are using branch protection. > +branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_NONE) := -mbranch-protection=none > + > ifeq ($(CONFIG_ARM64_PTR_AUTH),y) > branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all > branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret+leaf > @@ -73,9 +77,10 @@ branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pa > # we pass it only to the assembler. This option is utilized only in case of non > # integrated assemblers. > branch-prot-flags-$(CONFIG_AS_HAS_PAC) += -Wa,-march=armv8.3-a > -KBUILD_CFLAGS += $(branch-prot-flags-y) > endif > > +KBUILD_CFLAGS += $(branch-prot-flags-y) > + > ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) > KBUILD_CPPFLAGS += -mbig-endian > CHECKFLAGS += -D__AARCH64EB__ > -- > 2.20.1 > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel