Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1367617imi; Sat, 23 Jul 2022 03:51:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJuaREXtmcy4FnjBygI0j6e9absYROAtdooP7+kPVYk+GY46XFcaogszy+kDpzY6TWTXTT X-Received: by 2002:a17:902:cf12:b0:16c:a263:62b8 with SMTP id i18-20020a170902cf1200b0016ca26362b8mr3881899plg.31.1658573507743; Sat, 23 Jul 2022 03:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573507; cv=none; d=google.com; s=arc-20160816; b=jUcQD3GKwEbfeWsDWSoS8JzmaneiUSG3xX69THhmbVJhQKq1hTs/TUNkn285B+nXgq O1/diYZSUWress1p+QsyeUFmZyR5jl6jSoMRgOU3rN9O6tshIbMJ6vHsIfRMMciVu499 YKjSY3zrT75a8OSHctQad05OR+7sDsXEtElOXsui3BYSNrJtRXbJDokLfUhG6WfLGC16 7M+YUGUS2ttMwpbcA7qntnLmkdE4qcio017Q7MPsXI6o+Bk9Em42zFKWPW8t7cbT/ap3 36L/NanQDa+DJOuuTmJZGMCFkQG477ZoC0xo9U9DFyxEemGscjZmG41ghUeJLDKVXOp2 KLow== 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=OXmGIUBvj6+LJ1GjMluSH5MxTG8muPlKoRpxZeg3P5E=; b=ERQt4B0vHgfiFzcR4u98q3/R7eXrCqp4s9WoRmVhKM78ZS4zzAnfNNq7NwWgGwYGC2 +I19uOhIizVXUizEqHgUNQGRHFxcfkePlYdfbSnX/uTppEI0mZQJJqM7Q4CnnSELmdWw itvM7H8/4U40PO3+OmOUsMX+Y/UR/i9Ao4mMTCFGgmKZnL3P0YjJoJwAH2DOk1BKJgSh yprleI+nWoyhvJdFCcvwTDdTG/C4oMOthF93zaUIqw1b32YmyRDoRvqCgz0PHbokWtsy enBy5fMgsZA2w/Hr4EIj7KbtMd3eFnfK0Xy+rEh8EfInwJ/ar1a5xq91cUaX2zXKXY5O I5RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mE3zeWye; 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 d3-20020a631d03000000b003fae0c67055si8332465pgd.777.2022.07.23.03.51.32; Sat, 23 Jul 2022 03:51:47 -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=mE3zeWye; 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 S238123AbiGWKHM (ORCPT + 99 others); Sat, 23 Jul 2022 06:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238447AbiGWKGu (ORCPT ); Sat, 23 Jul 2022 06:06:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFF67754C; Sat, 23 Jul 2022 03:01:03 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3088CB82C1B; Sat, 23 Jul 2022 10:00:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C0BCC341C0; Sat, 23 Jul 2022 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570441; bh=uKk+3Op0t3ZhHfR38XvrZeuKdiesDxkqpIqWRpOsNHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mE3zeWyeRQ8EHoaMX8HGYXHdP76ca8y5FBKy2NDopNZAH8Z9Ht/eX3na4HfjvHncg GHyZ5hkM0hMZwKNTIAv3EDCCcqS+twZIE+MTniMFB/NPB1+qpkuCJj5AbSSyQ4wHyH +3CcPjmc2eajJQE7n3tWvF3NsJvVX19ndOkT9VSs= 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 , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 088/148] x86/ftrace: Use alternative RET encoding Date: Sat, 23 Jul 2022 11:55:00 +0200 Message-Id: <20220723095249.100961896@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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 1f001e9da6bbf482311e45e48f53c2bd2179e59c upstream. Use the return thunk in ftrace trampolines, if needed. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov [cascardo: still copy return from ftrace_stub] [cascardo: use memcpy(text_gen_insn) as there is no __text_gen_insn] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/ftrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -308,7 +308,7 @@ union ftrace_op_code_union { } __attribute__((packed)); }; -#define RET_SIZE 1 + IS_ENABLED(CONFIG_SLS) +#define RET_SIZE (IS_ENABLED(CONFIG_RETPOLINE) ? 5 : 1 + IS_ENABLED(CONFIG_SLS)) static unsigned long create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) @@ -367,7 +367,10 @@ create_trampoline(struct ftrace_ops *ops /* The trampoline ends with ret(q) */ retq = (unsigned long)ftrace_stub; - ret = copy_from_kernel_nofault(ip, (void *)retq, RET_SIZE); + if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) + memcpy(ip, text_gen_insn(JMP32_INSN_OPCODE, ip, &__x86_return_thunk), JMP32_INSN_SIZE); + else + ret = copy_from_kernel_nofault(ip, (void *)retq, RET_SIZE); if (WARN_ON(ret < 0)) goto fail;