Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4583imw; Tue, 12 Jul 2022 13:22:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vApm7tl3ueik+I7wsvL1f96jnjbd84r/90ftEU0Afp66SRaMV9omDewJTPZiRs6H5lYqVN X-Received: by 2002:a05:6402:27c8:b0:43a:f392:8fdd with SMTP id c8-20020a05640227c800b0043af3928fddmr4663339ede.328.1657656939758; Tue, 12 Jul 2022 13:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657656939; cv=none; d=google.com; s=arc-20160816; b=QYHD6LSK+VrWTs6aUd4PkmsZivqm6mnIeI7d5I1tm689iD5HGj9XDnOqc9IDUJuheA NUPZUD9mCcN4gEihD251v0E8dT1UaxtiSD4ApSbg1prqubiV+wF3aGsJCvFC3P+fI0tr 4jGlzG+qIOjoARaMRoY9NMuQbrqkW1hqoMx+4DvSaWaKh64kkL2TCtmxmGcXlTr+dTWj tffFXsLzHkGZwbP65FW8kg2oNf0fV7xzGC0/05vcO7o2d9lx+DdYiSqBYyVB0B/F3SP1 Dy06gvVnvlDYwJ0khxn0Wkz4I38M0mciFi+7MSaKFBaudF+RGzXZWW0BvnRYSkffu0xP nRsw== 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=Tz1Hy9bRtbR7yl9cScaIJnO/pMCp8sVDmtsIUHRupQtLoVnvx+Q3O5mgiPe1TjqX06 6DeJkWCr8uNYwnnxSIpt+zhz1uyl327RaYk5oEBNhzyLy3fHVuUOuZg1dYifwSE9IjKA 7vhhgqodSGk/jA75CdGoWLG+ODNtIDc8aVaMQLh9m/lnwGRj1bVuCSUl/EetHzfFV++T NaB/tMBfrkT9cJieapVcFFoG8swtdF6kEY36DnMErLzhs1TrYU9ret3nZCF83kXZLUa/ 3m84k4h+GfNr9MXtngkLoXkxqtrpfKZeBbOESWE0jxF6dda4QmG87wzkTyf402LsFvi2 W4Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xiGwttL5; 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 i24-20020a0564020f1800b0042b710e9bbesi1228233eda.566.2022.07.12.13.15.12; Tue, 12 Jul 2022 13:15:39 -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=xiGwttL5; 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 S234699AbiGLSwd (ORCPT + 99 others); Tue, 12 Jul 2022 14:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234159AbiGLSv4 (ORCPT ); Tue, 12 Jul 2022 14:51:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BEB9E5DC4; Tue, 12 Jul 2022 11:44:54 -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 D8C3060AC9; Tue, 12 Jul 2022 18:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7FBCC3411C; Tue, 12 Jul 2022 18:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651476; bh=uKk+3Op0t3ZhHfR38XvrZeuKdiesDxkqpIqWRpOsNHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xiGwttL5/AUC73h7egQi8J1B014h+oHtcfEjzh1QkfPnA49tjrdebBpu6Ic/KRqmU qpzHEEVuxsjzXCv8yX9fYRCaZGmlbThVPlYHd9N8TDTIRPuhMccilQNTM2BxQwoA8o 8hJg8ouPuMfxbhTL4C8aMCC8Os7a2KHnmu+ZQU1g= 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/130] x86/ftrace: Use alternative RET encoding Date: Tue, 12 Jul 2022 20:38:54 +0200 Message-Id: <20220712183250.522737769@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@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 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;