Received: by 2002:a9d:6f94:0:b0:61c:59f3:9354 with SMTP id h20csp1211otq; Tue, 12 Jul 2022 13:18:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1teJpbjgzrq9vTso1TD6a01Eqt3h8nQAztUfj5PKoOPqMew/Y5RgNQA4Uw7Tc81p0yY77wi X-Received: by 2002:a17:907:6295:b0:703:92b8:e113 with SMTP id nd21-20020a170907629500b0070392b8e113mr26006190ejc.594.1657656901976; Tue, 12 Jul 2022 13:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657656901; cv=none; d=google.com; s=arc-20160816; b=ZeHqquvdcxvBeHl4E/JD126FwjLLspM3Nugae1tIUgHFlWgFoRzq72goIVgyu3yhzw FPvDLZOF85tpJHL3ONI+WR7j245hg43kYbEJjFl8jC03ZhAd2GqStB6axLw5DDA0Il2i 9uwx6+XVmZ+6sTEV0C/6UdN0Isi4rxsYo6mj+3KWxkajkv10c28DUmGSewKJzXe1d79T yA3SYvFxaLV8o/fTAwN97uwgxltqxXW0dxYuFmq9d4LvucbrMZJ4YYix4/f+zskIHm36 nEw3zsZ/XnPs1djR/tI6mBKjcj7EBZkrYcLcK7KE95d1cTrIsuvYAkZCigHQx7xNfqD4 l57w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s2OIe08L2I8/qKSmbONV+bw7P+pP+XNZruKg9C0V/6M=; b=JqAGXUDQtEk+pH3u5ps90hWHVlMkYGG/OsaNXi0ZA3x258KjXSrlTLvXVamS3jz9O2 vRURMh86Adp5yG+rAQL8oKDl14ISDnWpWTHqgl3cZeLoYc0Hf9+4NamojIlKgZid9lm8 GxOzwe2NEIt6qlffwzFIDgkTdeKLM4F7sSj5BgQIzG/tzmBLBcp0prk+yFw/p18WicUq 5knJqh5zVcw/awjm//pmo/ty7G1+GDs5/YaoFsDfEzePSvqfChprFD055CphPaCmqSFx 5qp3wJVI0u5tTUry4VmNz9n8LkuN8akt+3MviqWHTbntJ5bC8UNeUBlI8mW2sxiPGWMX hYcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F0Ht89E2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a056402090e00b004356a5f330fsi17676489edz.445.2022.07.12.13.13.56; Tue, 12 Jul 2022 13:15:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F0Ht89E2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235700AbiGLTMK (ORCPT + 99 others); Tue, 12 Jul 2022 15:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235620AbiGLTKe (ORCPT ); Tue, 12 Jul 2022 15:10:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12C7C102081; Tue, 12 Jul 2022 11:52:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7750C60765; Tue, 12 Jul 2022 18:52:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4FFC3411C; Tue, 12 Jul 2022 18:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651971; bh=LcmL7A4xGcUiPi7IxZ5DfrFD9qmxQRA2uRcQDnvpRuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F0Ht89E27NY51QMdtrCWBB56Wrt+DCoZT9RZNY1kbRnrFONZnGpvUNys0nVoBHmtw H2mfnjjjeazj2VTvbYqaUzSJ+la5Ixl+NqA7QUuwN5zdnSkm1UWrxl9xuxBsJIQ/74 XQxtABmROzA2MZdmt9Zok2TgoTb+c5vt0Ea9enk4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Nick Desaulniers , Josh Poimboeuf , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.18 10/61] x86/retpoline: Use -mfunction-return Date: Tue, 12 Jul 2022 20:39:07 +0200 Message-Id: <20220712183237.359715627@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit 0b53c374b9eff2255a386f1f1cfb9a928e52a5ae upstream. Utilize -mfunction-return=thunk-extern when available to have the compiler replace RET instructions with direct JMPs to the symbol __x86_return_thunk. This does not affect assembler (.S) sources, only C sources. -mfunction-return=thunk-extern has been available since gcc 7.3 and clang 15. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Nick Desaulniers Reviewed-by: Josh Poimboeuf Tested-by: Nick Desaulniers Signed-off-by: Borislav Petkov Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/Makefile | 2 ++ arch/x86/include/asm/nospec-branch.h | 2 ++ arch/x86/lib/retpoline.S | 13 +++++++++++++ 3 files changed, 17 insertions(+) --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -15,11 +15,13 @@ endif ifdef CONFIG_CC_IS_GCC RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix) +RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register) endif ifdef CONFIG_CC_IS_CLANG RETPOLINE_CFLAGS := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := -mretpoline +RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) endif export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -123,6 +123,8 @@ typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; extern retpoline_thunk_t __x86_indirect_thunk_array[]; +extern void __x86_return_thunk(void); + #ifdef CONFIG_RETPOLINE #define GEN(reg) \ --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -67,3 +67,16 @@ SYM_CODE_END(__x86_indirect_thunk_array) #define GEN(reg) EXPORT_THUNK(reg) #include #undef GEN + +/* + * This function name is magical and is used by -mfunction-return=thunk-extern + * for the compiler to generate JMPs to it. + */ +SYM_CODE_START(__x86_return_thunk) + UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR + ret + int3 +SYM_CODE_END(__x86_return_thunk) + +__EXPORT_THUNK(__x86_return_thunk)