Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp457580imi; Fri, 22 Jul 2022 02:48:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vPIONolm4VyZEOQRbtoa/rsm/HsbBvpS5fX2y72la0IqheJJn7We6Nvq8C7i8W2KFrqwBB X-Received: by 2002:a05:6402:5518:b0:43a:9e32:b6fc with SMTP id fi24-20020a056402551800b0043a9e32b6fcmr2789415edb.252.1658483336757; Fri, 22 Jul 2022 02:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483336; cv=none; d=google.com; s=arc-20160816; b=AlgDHz2Tx0Pe5SM7Oz1bTa8NumqNvW7Cj2TuwKn1cNp1HHDqLuof85V0Lb9pbC7C7e BT1MKrM9YFkwcu6a2fcGntLtTTu7mLxMctjjQpQIwXaJdc+YN3UL2Q6McgntVy6zyp4C azQzT0IZDUmlTb3i3HmdstXDPnpqfAnnJpyooIvWTR8dtgFZtgsv9Z11ZWVH1b5xg9Iz 40N6gpS9OkD+KPu5EQG4uyAZL2gETDsqSquOyNvOvulHPabsR5e+zoDAhm3l3ViVq8KV scwHtz2e1z08VAd4pWud9a+scSTsA5hItEHP3lvS59GeE5jzzJ9qNTTIlpWyR65zVQwa nFSA== 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=PjbDoXwquK7hRWZnU2JpSKJuVitBxzqwAMquPwMTe7Hmavz5J9F7G+RnKvSjbExGxj cmLA93FFFFzUBT+C8iutDHixBHMs9dGUyQ9As0B0cxKaK9ADOesyciMIepl+sJHa4DYA zJuu62If1EvQdbRYOGxseToiItwPRXgtEiMqBnOC7HDIkS4A+SmnLaDl/pgMGU5GKx5N hIGhTf6PMXLrDkME4flZkvX9vpXElag3ShITk3hTc0hiWcLviNMiW1uPu2cCymugJVLo q+mNM8WygtIp3fNzjNrHUpYqHuGPzOHo2poDgtv3v0WipgeIzfALaj7ybw/HuTDJCYUz LFkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I8GELO2r; 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 c16-20020a05640227d000b0043a7de4ac20si2054036ede.500.2022.07.22.02.48.32; Fri, 22 Jul 2022 02:48: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=I8GELO2r; 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 S235150AbiGVJMB (ORCPT + 99 others); Fri, 22 Jul 2022 05:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbiGVJLW (ORCPT ); Fri, 22 Jul 2022 05:11:22 -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 C3EDAA9B8B; Fri, 22 Jul 2022 02:09:39 -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 1811861D7E; Fri, 22 Jul 2022 09:09:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E7ABC341C6; Fri, 22 Jul 2022 09:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658480978; bh=MXrrOTrkk/RGgoaIHAExHDTa3cUXx3Dyxn8DhpPAaWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8GELO2rZqVgPZ7K43lSxFxcj7eOx5MT7b/yRbVIUwSHKFGv8BtQKwz28VwZES9FL whpROAnFabtm2KyQYupRbW+wFfZFdghD/pZW3EROdDCx4NAuqYWZgDO7YDw4+Jx5M+ ddB4YpZUBMYUryUpKi0MQRetzqsWftp6J5Gg7V98= 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/70] x86/bpf: Use alternative RET encoding Date: Fri, 22 Jul 2022 11:07:11 +0200 Message-Id: <20220722090651.632392382@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722090650.665513668@linuxfoundation.org> References: <20220722090650.665513668@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 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;