]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Reject stack arguments if tail call reachable
authorYonghong Song <yonghong.song@linux.dev>
Wed, 13 May 2026 04:51:09 +0000 (21:51 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 May 2026 16:27:31 +0000 (09:27 -0700)
Tail calls are deprecated and will be replaced by indirect calls
in the future. Reject programs that combine tail calls with stack
arguments rather than adding complexity for a deprecated feature.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20260513045109.2392108-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index 1a734ab91a31750b969624eda3f7b30b27fcdce8..a10cc045057dbc17628971f63375475fcf70ff06 100644 (file)
@@ -5267,14 +5267,23 @@ continue_func:
         * this info will be utilized by JIT so that we will be preserving the
         * tail call counter throughout bpf2bpf calls combined with tailcalls
         */
-       if (tail_call_reachable)
+       if (tail_call_reachable) {
                for (tmp = idx; tmp >= 0; tmp = dinfo[tmp].caller) {
                        if (subprog[tmp].is_exception_cb) {
                                verbose(env, "cannot tail call within exception cb\n");
                                return -EINVAL;
                        }
+                       if (subprog[tmp].stack_arg_cnt) {
+                               verbose(env, "tail_calls are not allowed in programs with stack args\n");
+                               return -EINVAL;
+                       }
                        subprog[tmp].tail_call_reachable = true;
                }
+       } else if (!idx && subprog[0].has_tail_call && subprog[0].stack_arg_cnt) {
+               verbose(env, "tail_calls are not allowed in programs with stack args\n");
+               return -EINVAL;
+       }
+
        if (subprog[0].tail_call_reachable)
                env->prog->aux->tail_call_reachable = true;