Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp458897imi; Fri, 22 Jul 2022 02:50:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v82hhB9oW95ZgaU837EfTwd42czx1bYt1m2FGr+h+oKlb0yiut2lUn7cxOgA9oOyCquTCH X-Received: by 2002:a17:907:3e03:b0:722:e694:438 with SMTP id hp3-20020a1709073e0300b00722e6940438mr2434070ejc.755.1658483456100; Fri, 22 Jul 2022 02:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483456; cv=none; d=google.com; s=arc-20160816; b=wTnjBbtahX3jKmi2S4+PA72Adr9ezwIszOqoIocCnomdfEoDLzGdFIEF9ZkHfggB7D 4bLDIkNUR4md4Yn1xDP08S94OvOl7pBUw2PzO7A7Zc2M9G+cIUx3ALYEip7UUh9C8Yat /ncs2Inmmr153KIdgq0naRdeuxuLW9nxRozZs5lel/XwLPXmk9Njguw+f2keYhjGlacH g8fQ58KEyCxhBonTBkOwhQcfTaiocf5lS0qDm79ZnXXN6wwRDoefVt2BHHfKyGzj1SwU QoRzW2+J/5Iq1/FkKCru7fYsGW0KzJjerIbLkxjBDK6eYGaDRftuTv/Ofr8dLoalgRmu xOSw== 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=wf0KP0EZvf3AXmKYAHvr8gG5P8ZO29Ez4dgdJ9EveZY=; b=O6sDv2h1SxPmbc8BIuw5YdfwfnWPx80OCqmZmjKlxBclrpk9Vzm4O73efOlixCFt7W usud8d+9/Fsa54TCexhYTaI3PdGoUz3sXyhcTocUJHEG67ndssxlV5lJlchF4ap9UDrK w0grC7fRok9QSnbnJJaMZZw96cPFmzM2YcfH+P5oEcH+ECd3osfPKra8LM/I3E8aGVOt GS6k8MbpAEIOLSJMlqoerSostwLKgRdQqx+zcCgfd2R5YpJ76lR5lo6HKW/cagbmPARb Jv2oKefvXnCyga3g9ODR3xi1oAd15zIsVbErGDeszA1E1y/u1oi5CbEelKdt8T0X4p7x y5tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f9vGtcIU; 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 eb13-20020a0564020d0d00b0043795656e7dsi5664893edb.463.2022.07.22.02.50.31; Fri, 22 Jul 2022 02:50:56 -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=f9vGtcIU; 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 S235910AbiGVJT7 (ORCPT + 99 others); Fri, 22 Jul 2022 05:19:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236000AbiGVJTK (ORCPT ); Fri, 22 Jul 2022 05:19:10 -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 2E3CC140A7; Fri, 22 Jul 2022 02:13:17 -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 E0F5461F94; Fri, 22 Jul 2022 09:13:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECC78C341C6; Fri, 22 Jul 2022 09:13:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481196; bh=Lb9QWk96WPTUHtVIDQUUvFBZ7ad51b1dDmFNTdktXKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f9vGtcIUEx3TN3e+7YEVI1rQRQg3mp7wm4adcnwRRcn+smkglYIelUdZ2o8WVxiG0 XGLsgD188UlHvQMmCnlPLHBZzQzFV9fFR+7aHtxJRU2zgWEV/R4+rwTyvCxbxpveI0 pe02AmgyWM0V8eXOu+Tk+bFiRRwTb0V1vPrBYW84= 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.15 28/89] x86/retpoline: Use -mfunction-return Date: Fri, 22 Jul 2022 11:11:02 +0200 Message-Id: <20220722091134.942401952@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722091133.320803732@linuxfoundation.org> References: <20220722091133.320803732@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.8 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 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 [cascardo: RETPOLINE_CFLAGS is at Makefile] [cascardo: remove ANNOTATE_NOENDBR from __x86_return_thunk] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- Makefile | 2 ++ arch/x86/include/asm/nospec-branch.h | 2 ++ arch/x86/lib/retpoline.S | 12 ++++++++++++ 3 files changed, 16 insertions(+) --- a/Makefile +++ b/Makefile @@ -687,11 +687,13 @@ endif ifdef CONFIG_CC_IS_GCC RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) +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 @@ -120,6 +120,8 @@ _ASM_PTR " 999b\n\t" \ ".popsection\n\t" +extern void __x86_return_thunk(void); + #ifdef CONFIG_RETPOLINE typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -66,3 +66,15 @@ 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 + ret + int3 +SYM_CODE_END(__x86_return_thunk) + +__EXPORT_THUNK(__x86_return_thunk)