• Yonghong Song's avatar
    bpf: Set the number of exception entries properly for subprograms · c4c0bdc0
    Yonghong Song authored
    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: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    c4c0bdc0
verifier.c 318 KB