Skip to content

Commit 9b1da12

Browse files
puranjaymohanKernel Patches Daemon
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]>
1 parent e9c1c2d commit 9b1da12

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);
@@ -3292,9 +3293,8 @@ static bool find_from_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)
32923293
rcu_read_unlock();
32933294
if (!prog)
32943295
return true;
3295-
if (bpf_is_subprog(prog))
3296-
return true;
3297-
ctxp->prog = prog;
3296+
/* Make sure we return the main prog if we found a subprog */
3297+
ctxp->prog = prog->aux->main_prog_aux->prog;
32983298
return false;
32993299
}
33003300

kernel/bpf/verifier.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21597,6 +21597,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2159721597
func[i]->aux->func_info_cnt = prog->aux->func_info_cnt;
2159821598
func[i]->aux->poke_tab = prog->aux->poke_tab;
2159921599
func[i]->aux->size_poke_tab = prog->aux->size_poke_tab;
21600+
func[i]->aux->main_prog_aux = prog->aux;
2160021601

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

0 commit comments

Comments
 (0)