Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1368579imi; Sat, 23 Jul 2022 03:54:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3ugqNLdjpKLIwHRwSJ4XR2cmcJYhTGLrTcUq7YyDdVJk0Ed4OZWpC+Z1T64+iOKRPoSYH X-Received: by 2002:a17:906:5d16:b0:72f:248d:525a with SMTP id g22-20020a1709065d1600b0072f248d525amr3208093ejt.441.1658573640110; Sat, 23 Jul 2022 03:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573640; cv=none; d=google.com; s=arc-20160816; b=Tpc9lB787HtkLs8WW+bf+IwzpOJPuWP6AqVw7Eu+MQw4AQphUY5OgMuFRIw01NW7To LKsK1XYRpm9aMTh1irXwbm9Y1vPZrGucFw+LaUFshQOhWod6GHhHw1eYLbJK3HdE0oo6 I0d2NrAy0Tcj6Vu2b0h6Kz5vDK3d6XsrNRiC8eR7dSIo9BV6MHCH3IcsxyMPGUZbAMRS KVLRCV3gTnwfQuNFJPDVC4V80tLng2y9jI7k+7tbTY8ZBuwjxwNQz+dubRM27oOZ3sf/ VMWDmAL8yFyz2WC8lnKtBHWmieWslyNg8lE1/1TKX2AdaMjeg//l5PgspJLzHefbCdVx d7Cg== 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=TaeOpd0YMbr34YonikFU6sj3r7c7Yma7pCKHXDhSq5s=; b=WJX4afyEL4y/kQXtMeNNLD2F3EB46bZN8qCDkxB17QMP+6kUtnL/TmldZJGQcimDm5 kYv80KkFTWUU//TsRtNHyflggy9/Ra0KRgPopTdeNy3JS5udPPsY3IKXg3avTCk4pUBF I3s+6se02VUhhC50mhJvr+eLawncYbbcyELr/DODx8eG1gbA/jiDaqlf2ASG4Z7LojA6 dXuPopW6tJSZ2VDbBy1WL3ku1zhgj/wT8FjFeMNZwdUHIk5gwmlihAd6UW3/cpbsAXVb osdalk7iG2MUAjFy64RCWIF8vJp7g2Gax7Bx3j3kWVMc9KTpACPkoBclMWeMIkCmjn3Z RwQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1ZYzrpfZ; 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 fi11-20020a170906da0b00b007269fc5cc4fsi7475701ejb.212.2022.07.23.03.53.35; Sat, 23 Jul 2022 03:54:00 -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=1ZYzrpfZ; 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 S238593AbiGWKHW (ORCPT + 99 others); Sat, 23 Jul 2022 06:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238475AbiGWKGy (ORCPT ); Sat, 23 Jul 2022 06:06:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFED377546; Sat, 23 Jul 2022 03:01:06 -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 027F4B82C21; Sat, 23 Jul 2022 10:00:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B7B9C341C0; Sat, 23 Jul 2022 10:00:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570444; bh=QtnsdZLxc5e//iy3s2gLvf5/wn1Pnwcij+P+Wg6G5ag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ZYzrpfZRDLnwLz4epgHmUuqyEgbtu4ecHLrb4yrSdUKT47jOnJwwKmKgQYKNNV5M wjXujk19fAEiaQo8C5T5fMh2YD+mRLEaeTnUpjmFf9yVRLaqg4xfzimMq5DGWQxe/I 3+rSyFapyoYVHUB+sPKzz2yKjJYZmz9aB4VzJQcE= 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 089/148] x86/bpf: Use alternative RET encoding Date: Sat, 23 Jul 2022 11:55:01 +0200 Message-Id: <20220723095249.358079262@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 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 [bwh: Backported to 5.10: add the necessary cnt variable to emit_return()] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/net/bpf_jit_comp.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -399,6 +399,22 @@ static void emit_indirect_jump(u8 **ppro *pprog = prog; } +static void emit_return(u8 **pprog, u8 *ip) +{ + u8 *prog = *pprog; + int cnt = 0; + + 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: * @@ -1443,7 +1459,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: @@ -1884,7 +1900,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;