lkml.org 
[lkml]   [2022]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.10 089/148] x86/bpf: Use alternative RET encoding
    Date
    From: Peter Zijlstra <peterz@infradead.org>

    commit d77cfe594ad50e0bf95d457e02ccd578791b2a15 upstream.

    Use the return thunk in eBPF generated code, if needed.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
    [bwh: Backported to 5.10: add the necessary cnt variable to emit_return()]
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    ---
    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;

    \
     
     \ /
      Last update: 2022-07-23 12:08    [W:4.224 / U:0.032 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site