Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp454241imi; Fri, 22 Jul 2022 02:44:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1smNWPq6KJCNiF/u4GD+h3jcBn0jWygJH5SDnWARlZHHC8qVtKls6dfBLqG8s60hGoehd4s X-Received: by 2002:aa7:991a:0:b0:52a:c5df:e17f with SMTP id z26-20020aa7991a000000b0052ac5dfe17fmr2924833pff.52.1658483048864; Fri, 22 Jul 2022 02:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483048; cv=none; d=google.com; s=arc-20160816; b=PW3GcI+BV+w9e3RoNAxkRjSxnFnOZjGpsjxgowspmL90G7pTWSdrPIgVqkzff82VTI Xsdod9KPP3T2z342o7dIfadfOz78rfRnttyfB/G71NfRJn+8bJFs2g1GeGf9BHuvIibo BuWiY+SzDrXzA6qISQ9KAXXVrPz1Z6C6ckIsaXxA5dWYvYyVQqbaNIYw8dMG53esI11Q TGz2db9x8mf+qSdu7n11Z55+YddvuUULl7GX9pHxul9PrpuxID5aaEcipX4Ku0shRubM snk5PrT0irk42v4paP6Io/9GQplmwfcQfSigkpfeTp25v1CdPS3d1jOGjdZsRP4sYUF/ EwsA== 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=kcxFijiCaAPHRVOCLFs5WLAvV4k93kPmB53jQbLOGpE=; b=ZE8caHDbfNEA0apJGBld8wQ+pAcprJInHCaWNQyDdEFmSDfaMIegitQvRNr97VL4o/ eSiFPDeaJzQBpmyS7jKESmHy7ec2iwY+74PrX+hKALuLIvCd46Vyykm2zKTjVf7SxGXm zfBum7SKfKqpAguz4glIqwbmkYl75r3uHPzEOQsBAjeNnas5IgIsRLNTGybsCnizu9f9 vQWWVZIxNZXuBGRcDTOHM/7yFlRwdU/4n/ppH2brJKtQVc0OkHgm/f55lLZagAOL1PDA +vQgA2WMigAkmdszADgiekiqjgFTxrxR/jJR0z05IVa168u78n8S/n1kQvkg3zbydbBN xiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HHfnuXdG; 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 190-20020a6217c7000000b0052b206007bcsi5047719pfx.237.2022.07.22.02.43.54; Fri, 22 Jul 2022 02:44:08 -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=HHfnuXdG; 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 S235841AbiGVJSF (ORCPT + 99 others); Fri, 22 Jul 2022 05:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235814AbiGVJRj (ORCPT ); Fri, 22 Jul 2022 05:17:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B07B8525; Fri, 22 Jul 2022 02:12:35 -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 CB2E761F76; Fri, 22 Jul 2022 09:12:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 976F3C341CA; Fri, 22 Jul 2022 09:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481154; bh=oCx4n0QKS697SzZZs9wYUrdZdNcVzFWsGdUnsN5H64Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HHfnuXdG2CUe4y/5KwdkPir24dDHKoHpMwR0S1a65vDdY/mmI43YpxEFnajMzeoDK 5y7UKXti6hRik6a1scF4gnHVcdP3d+RiIQiQjSBgXSAde/vG6IGvLAQI5g8SNmtffj k6TRQBtEsYPiVdjR+I51XDGZOMRiDGw3CUZg+XoQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Alexei Starovoitov , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.15 14/89] x86/retpoline: Create a retpoline thunk array Date: Fri, 22 Jul 2022 11:10:48 +0200 Message-Id: <20220722091134.171268362@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 1a6f74429c42a3854980359a758e222005712aee upstream. Stick all the retpolines in a single symbol and have the individual thunks as inner labels, this should guarantee thunk order and layout. Previously there were 16 (or rather 15 without rsp) separate symbols and a toolchain might reasonably expect it could displace them however it liked, with disregard for their relative position. However, now they're part of a larger symbol. Any change to their relative position would disrupt this larger _array symbol and thus not be sound. This is the same reasoning used for data symbols. On their own there is no guarantee about their relative position wrt to one aonther, but we're still able to do arrays because an array as a whole is a single larger symbol. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Borislav Petkov Acked-by: Josh Poimboeuf Tested-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20211026120310.169659320@infradead.org Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 8 +++++++- arch/x86/lib/retpoline.S | 14 +++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -12,6 +12,8 @@ #include #include +#define RETPOLINE_THUNK_SIZE 32 + /* * Fill the CPU return stack buffer. * @@ -120,11 +122,15 @@ #ifdef CONFIG_RETPOLINE +typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; + #define GEN(reg) \ - extern asmlinkage void __x86_indirect_thunk_ ## reg (void); + extern retpoline_thunk_t __x86_indirect_thunk_ ## reg; #include #undef GEN +extern retpoline_thunk_t __x86_indirect_thunk_array[]; + #ifdef CONFIG_X86_64 /* --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -28,16 +28,14 @@ .macro THUNK reg - .align 32 - -SYM_FUNC_START(__x86_indirect_thunk_\reg) + .align RETPOLINE_THUNK_SIZE +SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) + UNWIND_HINT_EMPTY ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \ __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg; int3), X86_FEATURE_RETPOLINE_LFENCE -SYM_FUNC_END(__x86_indirect_thunk_\reg) - .endm /* @@ -55,10 +53,16 @@ SYM_FUNC_END(__x86_indirect_thunk_\reg) #define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym) #define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg) + .align RETPOLINE_THUNK_SIZE +SYM_CODE_START(__x86_indirect_thunk_array) + #define GEN(reg) THUNK reg #include #undef GEN + .align RETPOLINE_THUNK_SIZE +SYM_CODE_END(__x86_indirect_thunk_array) + #define GEN(reg) EXPORT_THUNK(reg) #include #undef GEN