]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf: core: introduce main_prog_aux for stream access
authorPuranjay Mohan <puranjay@kernel.org>
Thu, 11 Sep 2025 14:58:01 +0000 (14:58 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 11 Sep 2025 20:00:43 +0000 (13:00 -0700)
BPF streams are only valid for the main programs, to make it easier to
access streams from subprogs, introduce main_prog_aux in struct
bpf_prog_aux.

prog->aux->main_prog_aux = prog->aux, for main programs and
prog->aux->main_prog_aux = main_prog->aux, for subprograms.

Make bpf_prog_find_from_stack() use the added main_prog_aux to return
the mainprog when a subprog is found on the stack.

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20250911145808.58042-3-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/core.c
kernel/bpf/verifier.c

index 8f6e87f0f3a89d8fd3eca113000a825c2eb9544b..d133171c4d2a9a121add8f48d4482e488cc298d4 100644 (file)
@@ -1633,6 +1633,7 @@ struct bpf_prog_aux {
        /* function name for valid attach_btf_id */
        const char *attach_func_name;
        struct bpf_prog **func;
+       struct bpf_prog_aux *main_prog_aux;
        void *jit_data; /* JIT specific data. arch dependent */
        struct bpf_jit_poke_descriptor *poke_tab;
        struct bpf_kfunc_desc_tab *kfunc_tab;
index e6801945910672e423f88e6e1294ce5b821354ff..1cda2589d4b35cdf09f7dd8e0c992ef09e20a1a3 100644 (file)
@@ -120,6 +120,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag
 
        fp->pages = size / PAGE_SIZE;
        fp->aux = aux;
+       fp->aux->main_prog_aux = aux;
        fp->aux->prog = fp;
        fp->jit_requested = ebpf_jit_enabled();
        fp->blinding_requested = bpf_jit_blinding_enabled(fp);
@@ -3297,9 +3298,8 @@ static bool find_from_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)
        rcu_read_unlock();
        if (!prog)
                return true;
-       if (bpf_is_subprog(prog))
-               return true;
-       ctxp->prog = prog;
+       /* Make sure we return the main prog if we found a subprog */
+       ctxp->prog = prog->aux->main_prog_aux->prog;
        return false;
 }
 
index b8b510a25b0315f229e8bd316e8f6ec2ce620c49..17fe623400a5bcd7faf900c92e54994be952c628 100644 (file)
@@ -21601,6 +21601,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
                func[i]->aux->func_info_cnt = prog->aux->func_info_cnt;
                func[i]->aux->poke_tab = prog->aux->poke_tab;
                func[i]->aux->size_poke_tab = prog->aux->size_poke_tab;
+               func[i]->aux->main_prog_aux = prog->aux;
 
                for (j = 0; j < prog->aux->size_poke_tab; j++) {
                        struct bpf_jit_poke_descriptor *poke;