OSDN Git Service

bpf: Set the number of exception entries properly for subprograms
authorYonghong Song <yhs@fb.com>
Wed, 24 Jun 2020 00:10:54 +0000 (17:10 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 24 Jun 2020 00:27:37 +0000 (17:27 -0700)
commitc4c0bdc0d2d084ed847c7066bdf59fe2cd25aa17
tree111b9157be6a6cf063521db22c32d2c7ea14f67a
parent9c82a63cf3701b78cd092c69c3e75ff806837194
bpf: Set the number of exception entries properly for subprograms

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
   #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>
kernel/bpf/verifier.c