Skip to content

Commit 70f2354

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
bpf: core: introduce main_prog_aux for stream access
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 <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0460484 commit 70f2354

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,7 @@ struct bpf_prog_aux {
16331633
/* function name for valid attach_btf_id */
16341634
const char *attach_func_name;
16351635
struct bpf_prog **func;
1636+
struct bpf_prog_aux *main_prog_aux;
16361637
void *jit_data; /* JIT specific data. arch dependent */
16371638
struct bpf_jit_poke_descriptor *poke_tab;
16381639
struct bpf_kfunc_desc_tab *kfunc_tab;

kernel/bpf/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag
120120

121121
fp->pages = size / PAGE_SIZE;
122122
fp->aux = aux;
123+
fp->aux->main_prog_aux = aux;
123124
fp->aux->prog = fp;
124125
fp->jit_requested = ebpf_jit_enabled();
125126
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)
32973298
rcu_read_unlock();
32983299
if (!prog)
32993300
return true;
3300-
if (bpf_is_subprog(prog))
3301-
return true;
3302-
ctxp->prog = prog;
3301+
/* Make sure we return the main prog if we found a subprog */
3302+
ctxp->prog = prog->aux->main_prog_aux->prog;
33033303
return false;
33043304
}
33053305

kernel/bpf/verifier.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21601,6 +21601,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2160121601
func[i]->aux->func_info_cnt = prog->aux->func_info_cnt;
2160221602
func[i]->aux->poke_tab = prog->aux->poke_tab;
2160321603
func[i]->aux->size_poke_tab = prog->aux->size_poke_tab;
21604+
func[i]->aux->main_prog_aux = prog->aux;
2160421605

2160521606
for (j = 0; j < prog->aux->size_poke_tab; j++) {
2160621607
struct bpf_jit_poke_descriptor *poke;

0 commit comments

Comments
 (0)