Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1331544ybz; Thu, 16 Apr 2020 07:21:13 -0700 (PDT) X-Google-Smtp-Source: APiQypIfZAqOK4oL5PIXoiuS2J5WbOt+/RB8aeS/h3jqOedAdbbeZm52yh5emxMDnk/ClcfLTb6h X-Received: by 2002:a05:6402:1215:: with SMTP id c21mr9115708edw.128.1587046872559; Thu, 16 Apr 2020 07:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587046872; cv=none; d=google.com; s=arc-20160816; b=0bNwvLOMI00lDiEW2+1ET46B1nlDMMQAjoWbjrJg+dzYjtILnxT+z3QgALAZN1vZu4 lOQdKLcKm9iLq87Omvc5lIXPTXqb4uAJhrO+7CP2tLSggOqK/XVypotSB9sYi/28echQ mDSxfPaQW6To2YXg+zbMkNQw8ZFbPDNvnBEj4/oZVE8NFu6+wlsqXDHJ9hCqruZzlHG0 1gJ4kvNLFXnweBVu5/m76qCV2BhdfCH/2mQKBs1hSv3K2WRJkLHvy88gr06T2aiFy3od y5JgNykgo/WgoGGbOVZnvVpV7y5mEwjGpw36WlKzXiZxpBfJZFX1v+2rrDfpytU3u69T Qt1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VwU6hArJXxkdlT4zjc6s6NDI7d5TrQ73NIWf+1F/R1w=; b=oyDiwC6DLzkdRWmgDEsUNO7LspI+zgMf10QS5FsMdelr823YzdKVXJCyAbdSCI6NXX T/GvQYdyX+5hAN1ZUYnx70F4BAGDzlJ2e5GcCJ9rZ3aYtPVX6xI/zadNnivWKa+j6PZh r5yhqGTpWjKi7rhEt85lCGZVqelcc/UbQ+b7mKUaEqNE9L3HxDWG/dtb5PUnTgxHMv3a whiU6jLoUQ2o5buYYaOqNThGYJI8WKmIcLjU3gQNh5/06KL0Y0M4VvGGWdjz2by8aS6i TOGWDc1ugaDhFD/Hk3jNn/D4cR0T4UdaHTBzB99WrQAsFm5ZxuNxzxErlM6d9id8al6Q EXfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S7D8lJzE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si11820376ejc.152.2020.04.16.07.20.48; Thu, 16 Apr 2020 07:21:12 -0700 (PDT) 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=@kernel.org header.s=default header.b=S7D8lJzE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393838AbgDPOQt (ORCPT + 99 others); Thu, 16 Apr 2020 10:16:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:38372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389235AbgDPNwH (ORCPT ); Thu, 16 Apr 2020 09:52:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27AF42063A; Thu, 16 Apr 2020 13:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587045126; bh=mDp69Lb0S9CHcaaZ0egFJJ01Dml5CiR2KtDUpVg1cCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7D8lJzEax4zjAAC4X6zbF5+yHZc2seRtQhcv4qO4t2xqL0rKtk2UuGinfssbGp/h 8I9us/6Kc4WPj1f96z1wZ9OQzSEfUmdhr93oaElrtztF9zcKxRn4OGFVIBl0n+oa9M TIMmAebpOQSlfb3SYO1yQNq+LHQ6H3yeA65US7Jk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Szabolcs Nagy , Mark Brown , Catalin Marinas Subject: [PATCH 5.4 217/232] arm64: Always force a branch protection mode when the compiler has one Date: Thu, 16 Apr 2020 15:25:11 +0200 Message-Id: <20200416131342.629504096@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Brown commit b8fdef311a0bd9223f10754f94fdcf1a594a3457 upstream. 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. [This is a reworked version of b8fdef311a0bd9223f1075 ("arm64: Always force a branch protection mode when the compiler has one") for backport. Kernels prior to 74afda4016a7 ("arm64: compile the kernel with ptrauth return address signing") don't have any Makefile machinery for forcing on pointer auth but still have issues if the compiler defaults it on so need this reworked version. -- broonie] Fixes: 7503197562567 (arm64: add basic pointer authentication support) Reported-by: Szabolcs Nagy Signed-off-by: Mark Brown Cc: stable@vger.kernel.org [catalin.marinas@arm.com: remove Kconfig option in favour of Makefile check] Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/Makefile | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -72,6 +72,10 @@ stack_protector_prepare: prepare0 include/generated/asm-offsets.h)) endif +# Ensure that if the compiler supports branch protection we default it +# off. +KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none) + ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__AARCH64EB__