Skip to content

Commit fad8040

Browse files
aspskAlexei Starovoitov
authored andcommitted
bpf: cleanup aux->used_maps after jit
In commit b4ce592 ("bpf, x86: add new map type: instructions array") env->used_map was copied to func[i]->aux->used_maps before jitting. Clear these fields out after jitting such that pointer to freed memory (env->used_maps is freed later) are not kept in a live data structure. The reason why the copies were initially added is explained in https://lore.kernel.org/bpf/20251105090410.1250500-1-a.s.protopopov@gmail.com Suggested-by: Alexei Starovoitov <ast@kernel.org> Fixes: b4ce592 ("bpf, x86: add new map type: instructions array") Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com> Link: https://lore.kernel.org/r/20251124151515.2543403-1-a.s.protopopov@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent c427320 commit fad8040

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22266,6 +22266,15 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2226622266
cond_resched();
2226722267
}
2226822268

22269+
/*
22270+
* Cleanup func[i]->aux fields which aren't required
22271+
* or can become invalid in future
22272+
*/
22273+
for (i = 0; i < env->subprog_cnt; i++) {
22274+
func[i]->aux->used_maps = NULL;
22275+
func[i]->aux->used_map_cnt = 0;
22276+
}
22277+
2226922278
/* finally lock prog and jit images for all functions and
2227022279
* populate kallsysm. Begin at the first subprogram, since
2227122280
* bpf_prog_load will add the kallsyms for the main program.

0 commit comments

Comments
 (0)