Skip to content

Commit 0108a4e

Browse files
kmjohansenAlexei Starovoitov
authored andcommitted
bpf: ensure main program has an extable
When subprograms are in use, the main program is not jit'd after the subprograms because jit_subprogs sets a value for prog->bpf_func upon success. Subsequent calls to the JIT are bypassed when this value is non-NULL. This leads to a situation where the main program and its func[0] counterpart are both in the bpf kallsyms tree, but only func[0] has an extable. Extables are only created during JIT. Now there are two nearly identical program ksym entries in the tree, but only one has an extable. Depending upon how the entries are placed, there's a chance that a fault will call search_extable on the aux with the NULL entry. Since jit_subprogs already copies state from func[0] to the main program, include the extable pointer in this state duplication. Additionally, ensure that the copy of the main program in func[0] is not added to the bpf_prog_kallsyms table. Instead, let the main program get added later in bpf_prog_load(). This ensures there is only a single copy of the main program in the kallsyms table, and that its tag matches the tag observed by tooling like bpftool. Cc: [email protected] Fixes: 1c2a088 ("bpf: x64: add JIT support for multi-function programs") Signed-off-by: Krister Johansen <[email protected]> Acked-by: Yonghong Song <[email protected]> Acked-by: Ilya Leoshkevich <[email protected]> Tested-by: Ilya Leoshkevich <[email protected]> Link: https://lore.kernel.org/r/6de9b2f4b4724ef56efbb0339daaa66c8b68b1e7.1686616663.git.kjlx@templeofstupid.com Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ad96f1c commit 0108a4e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17217,9 +17217,10 @@ static int jit_subprogs(struct bpf_verifier_env *env)
1721717217
}
1721817218

1721917219
/* finally lock prog and jit images for all functions and
17220-
* populate kallsysm
17220+
* populate kallsysm. Begin at the first subprogram, since
17221+
* bpf_prog_load will add the kallsyms for the main program.
1722117222
*/
17222-
for (i = 0; i < env->subprog_cnt; i++) {
17223+
for (i = 1; i < env->subprog_cnt; i++) {
1722317224
bpf_prog_lock_ro(func[i]);
1722417225
bpf_prog_kallsyms_add(func[i]);
1722517226
}
@@ -17245,6 +17246,8 @@ static int jit_subprogs(struct bpf_verifier_env *env)
1724517246
prog->jited = 1;
1724617247
prog->bpf_func = func[0]->bpf_func;
1724717248
prog->jited_len = func[0]->jited_len;
17249+
prog->aux->extable = func[0]->aux->extable;
17250+
prog->aux->num_exentries = func[0]->aux->num_exentries;
1724817251
prog->aux->func = func;
1724917252
prog->aux->func_cnt = env->subprog_cnt;
1725017253
bpf_prog_jit_attempt_done(prog);

0 commit comments

Comments
 (0)