diff options
Diffstat (limited to 'kernel/bpf/core.c')
| -rw-r--r-- | kernel/bpf/core.c | 21 | 
1 files changed, 13 insertions, 8 deletions
| diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 5d1650af899d..e4568d44e827 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2366,8 +2366,7 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,  					 const struct bpf_insn *insn)  {  	/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON -	 * is not working properly, or interpreter is being used when -	 * prog->jit_requested is not 0, so warn about it! +	 * is not working properly, so warn about it!  	 */  	WARN_ON_ONCE(1);  	return 0; @@ -2468,8 +2467,9 @@ out:  	return ret;  } -static void bpf_prog_select_func(struct bpf_prog *fp) +static bool bpf_prog_select_interpreter(struct bpf_prog *fp)  { +	bool select_interpreter = false;  #ifndef CONFIG_BPF_JIT_ALWAYS_ON  	u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);  	u32 idx = (round_up(stack_depth, 32) / 32) - 1; @@ -2478,15 +2478,16 @@ static void bpf_prog_select_func(struct bpf_prog *fp)  	 * But for non-JITed programs, we don't need bpf_func, so no bounds  	 * check needed.  	 */ -	if (!fp->jit_requested && -	    !WARN_ON_ONCE(idx >= ARRAY_SIZE(interpreters))) { +	if (idx < ARRAY_SIZE(interpreters)) {  		fp->bpf_func = interpreters[idx]; +		select_interpreter = true;  	} else {  		fp->bpf_func = __bpf_prog_ret0_warn;  	}  #else  	fp->bpf_func = __bpf_prog_ret0_warn;  #endif +	return select_interpreter;  }  /** @@ -2505,7 +2506,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)  	/* In case of BPF to BPF calls, verifier did all the prep  	 * work with regards to JITing, etc.  	 */ -	bool jit_needed = fp->jit_requested; +	bool jit_needed = false;  	if (fp->bpf_func)  		goto finalize; @@ -2514,7 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)  	    bpf_prog_has_kfunc_call(fp))  		jit_needed = true; -	bpf_prog_select_func(fp); +	if (!bpf_prog_select_interpreter(fp)) +		jit_needed = true;  	/* eBPF JITs can rewrite the program in case constant  	 * blinding is active. However, in case of error during @@ -3024,7 +3026,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);  /* Always built-in helper functions. */  const struct bpf_func_proto bpf_tail_call_proto = { -	.func		= NULL, +	/* func is unused for tail_call, we set it to pass the +	 * get_helper_proto check +	 */ +	.func		= BPF_PTR_POISON,  	.gpl_only	= false,  	.ret_type	= RET_VOID,  	.arg1_type	= ARG_PTR_TO_CTX, | 
