Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4700734imw; Tue, 12 Jul 2022 12:40:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUK8htCYNJz4zqScUaeWUJsAJSDRxWtcin1S/a02kMQl4iLRO/xwn4mSPaSjVETER5lQtQ X-Received: by 2002:a05:6a00:158e:b0:52a:e628:8b3b with SMTP id u14-20020a056a00158e00b0052ae6288b3bmr5489452pfk.80.1657654858135; Tue, 12 Jul 2022 12:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654858; cv=none; d=google.com; s=arc-20160816; b=OPr5NXoRPGFJ78xD8d8cZtnjC5zLaQIwFNKaXowSjExHPdCRRmmhAFguzsxb04wlc+ VL0spux6k7+Yj/tyhwrqPKKneXlQwLihG9MvuUt22Omupf5Pc8/5nW7ITbZwJOO1OHh3 KXDr1n9qBc0fRYIru0lgLbY/Vjd+kuG+4Pw/mwXG29phEss2R4Kuxdkjx4ptVvYZlD3g x7mlAvOU1cG7lKl2quIK/nkDrfS6d6mGwdij8f8dS92vxQ100V3yhPpht5k8g17Z2kXc 2fJ2qSLklV2nV6JEXAf0bi3xRy0NvBenD+YDpRNSpSCC0tVZEAGPzb5TONdPPMPpL46Q MPQQ== 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=VyUddBih8hosEHpM/SXhZrsTEi1zz+8W78WmBqc0w/o=; b=BoiPyGiOXzk4V8z91Ydms2IanRG0imNBdNWLAHPoHvQ9aj9lImiEc3R0qcN0m2kX5i XRzDwD2hAF5HicUulxN1d/zuhq1FJodarx0XeCaFDrR0xrLsOXRoyjXKBykUiEZFS55n fJqz9o/TIDOckkGmKdivb3zBKJ1j4n5o76Jj/D1TVTpxObQnB3z3W8yRdqEtQIYni4Hz BZgd+XJBy0crY3dY/tKqEP++Xa9prh2b/JYacoehRThMaD6SxgNZ8UVEDzcm6wN046Q8 7B7Kf0QHzEwrdWIyLGQ7bO//86gtI9Af+gLpqjMeQ+CjAPlq8DHEbz6kaSn2k3uLks9q K3wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ipHmrddW; 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 x76-20020a63314f000000b003fdfb59ccdesi13651887pgx.841.2022.07.12.12.40.45; Tue, 12 Jul 2022 12:40:58 -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=ipHmrddW; 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 S235665AbiGLTIm (ORCPT + 99 others); Tue, 12 Jul 2022 15:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235550AbiGLTHz (ORCPT ); Tue, 12 Jul 2022 15:07:55 -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 BEC42E43D1; Tue, 12 Jul 2022 11:51:41 -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 A94B861491; Tue, 12 Jul 2022 18:51:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF782C3411C; Tue, 12 Jul 2022 18:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651898; bh=MXrrOTrkk/RGgoaIHAExHDTa3cUXx3Dyxn8DhpPAaWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ipHmrddWCTTacHSmkOtwR8SWm0lTgdBIuXm30dvmK9RMy/wYCpWtkfA/DMz0CXz5v xT2CVwaM7cE8hB0n/zE53IQIRdl7NJotz6L2u2x5ZZnqzZHstSoVO5BCAkHydoDOzQ FqL3VogMvwe6jqMYw1ZEcinhU+q/jsC7es+K3qsw= 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 Subject: [PATCH 5.18 16/61] x86/bpf: Use alternative RET encoding Date: Tue, 12 Jul 2022 20:39:13 +0200 Message-Id: <20220712183237.596015580@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 d77cfe594ad50e0bf95d457e02ccd578791b2a15 upstream. Use the return thunk in eBPF generated code, if needed. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/net/bpf_jit_comp.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -420,6 +420,21 @@ static void emit_indirect_jump(u8 **ppro *pprog = prog; } +static void emit_return(u8 **pprog, u8 *ip) +{ + u8 *prog = *pprog; + + if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) { + emit_jump(&prog, &__x86_return_thunk, ip); + } else { + EMIT1(0xC3); /* ret */ + if (IS_ENABLED(CONFIG_SLS)) + EMIT1(0xCC); /* int3 */ + } + + *pprog = prog; +} + /* * Generate the following code: * @@ -1680,7 +1695,7 @@ emit_jmp: ctx->cleanup_addr = proglen; pop_callee_regs(&prog, callee_regs_used); EMIT1(0xC9); /* leave */ - EMIT1(0xC3); /* ret */ + emit_return(&prog, image + addrs[i - 1] + (prog - temp)); break; default: @@ -2157,7 +2172,7 @@ int arch_prepare_bpf_trampoline(struct b if (flags & BPF_TRAMP_F_SKIP_FRAME) /* skip our return address and return to parent */ EMIT4(0x48, 0x83, 0xC4, 8); /* add rsp, 8 */ - EMIT1(0xC3); /* ret */ + emit_return(&prog, prog); /* Make sure the trampoline generation logic doesn't overflow */ if (WARN_ON_ONCE(prog > (u8 *)image_end - BPF_INSN_SAFETY)) { ret = -EFAULT;