Skip to content

Commit 9064bc6

Browse files
yonghong-songgregkh
authored andcommitted
bpf: Set the number of exception entries properly for subprograms
[ Upstream commit c4c0bdc ] Currently, if a bpf program has more than one subprograms, each program will be jitted separately. For programs with bpf-to-bpf calls the prog->aux->num_exentries is not setup properly. For example, with bpf_iter_netlink.c modified to force one function to be not inlined and with CONFIG_BPF_JIT_ALWAYS_ON the following error is seen: $ ./test_progs -n 3/3 ... libbpf: failed to load program 'iter/netlink' libbpf: failed to load object 'bpf_iter_netlink' libbpf: failed to load BPF skeleton 'bpf_iter_netlink': -4007 test_netlink:FAIL:bpf_iter_netlink__open_and_load skeleton open_and_load failed gregkh#3/3 netlink:FAIL The dmesg shows the following errors: ex gen bug which is triggered by the following code in arch/x86/net/bpf_jit_comp.c: if (excnt >= bpf_prog->aux->num_exentries) { pr_err("ex gen bug\n"); return -EFAULT; } This patch fixes the issue by computing proper num_exentries for each subprogram before calling JIT. Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 81cab38 commit 9064bc6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9613,7 +9613,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
96139613
int i, j, subprog_start, subprog_end = 0, len, subprog;
96149614
struct bpf_insn *insn;
96159615
void *old_bpf_func;
9616-
int err;
9616+
int err, num_exentries;
96179617

96189618
if (env->subprog_cnt <= 1)
96199619
return 0;
@@ -9688,6 +9688,14 @@ static int jit_subprogs(struct bpf_verifier_env *env)
96889688
func[i]->aux->nr_linfo = prog->aux->nr_linfo;
96899689
func[i]->aux->jited_linfo = prog->aux->jited_linfo;
96909690
func[i]->aux->linfo_idx = env->subprog_info[i].linfo_idx;
9691+
num_exentries = 0;
9692+
insn = func[i]->insnsi;
9693+
for (j = 0; j < func[i]->len; j++, insn++) {
9694+
if (BPF_CLASS(insn->code) == BPF_LDX &&
9695+
BPF_MODE(insn->code) == BPF_PROBE_MEM)
9696+
num_exentries++;
9697+
}
9698+
func[i]->aux->num_exentries = num_exentries;
96919699
func[i] = bpf_int_jit_compile(func[i]);
96929700
if (!func[i]->jited) {
96939701
err = -ENOTSUPP;

0 commit comments

Comments
 (0)