1. 09 Aug, 2019 3 commits
  2. 01 Aug, 2019 4 commits
    • Alexei Starovoitov's avatar
      selftests/bpf: tests for jmp to 1st insn · f1fc7249
      Alexei Starovoitov authored
      Add 2 tests that check JIT code generation to jumps to 1st insn.
      1st test is similar to syzbot reproducer.
      The backwards branch is never taken at runtime.
      2nd test has branch to 1st insn that executes.
      The test is written as two bpf functions, since it's not possible
      to construct valid single bpf program that jumps to 1st insn.
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      f1fc7249
    • Alexei Starovoitov's avatar
      bpf: fix x64 JIT code generation for jmp to 1st insn · 7c2e988f
      Alexei Starovoitov authored
      Introduction of bounded loops exposed old bug in x64 JIT.
      JIT maintains the array of offsets to the end of all instructions to
      compute jmp offsets.
      addrs[0] - offset of the end of the 1st insn (that includes prologue).
      addrs[1] - offset of the end of the 2nd insn.
      JIT didn't keep the offset of the beginning of the 1st insn,
      since classic BPF didn't have backward jumps and valid extended BPF
      couldn't have a branch to 1st insn, because it didn't allow loops.
      With bounded loops it's possible to construct a valid program that
      jumps backwards to the 1st insn.
      Fix JIT by computing:
      addrs[0] - offset of the end of prologue == start of the 1st insn.
      addrs[1] - offset of the end of 1st insn.
      
      v1->v2:
      - Yonghong noticed a bug in jit linfo.
        Fix it by passing 'addrs + 1' to bpf_prog_fill_jited_linfo(),
        since it expects insn_to_jit_off array to be offsets to last byte.
      
      Reported-by: syzbot+35101610ff3e83119b1b@syzkaller.appspotmail.com
      Fixes: 2589726d ("bpf: introduce bounded loops")
      Fixes: 0a14842f ("net: filter: Just In Time compiler for x86-64")
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      7c2e988f
    • Andrii Nakryiko's avatar
      libbpf: set BTF FD for prog only when there is supported .BTF.ext data · 3415ec64
      Andrii Nakryiko authored
      5d01ab7b ("libbpf: fix erroneous multi-closing of BTF FD")
      introduced backwards-compatibility issue, manifesting itself as -E2BIG
      error returned on program load due to unknown non-zero btf_fd attribute
      value for BPF_PROG_LOAD sys_bpf() sub-command.
      
      This patch fixes bug by ensuring that we only ever associate BTF FD with
      program if there is a BTF.ext data that was successfully loaded into
      kernel, which automatically means kernel supports func_info/line_info
      and associated BTF FD for progs (checked and ensured also by BTF
      sanitization code).
      
      Fixes: 5d01ab7b ("libbpf: fix erroneous multi-closing of BTF FD")
      Reported-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      3415ec64
    • Takshak Chahande's avatar
      libbpf : make libbpf_num_possible_cpus function thread safe · 56fbc241
      Takshak Chahande authored
      Having static variable `cpus` in libbpf_num_possible_cpus function
      without guarding it with mutex makes this function thread-unsafe.
      
      If multiple threads accessing this function, in the current form; it
      leads to incrementing the static variable value `cpus` in the multiple
      of total available CPUs.
      
      Used local stack variable to calculate the number of possible CPUs and
      then updated the static variable using WRITE_ONCE().
      
      Changes since v1:
       * added stack variable to calculate cpus
       * serialized static variable update using WRITE_ONCE()
       * fixed Fixes tag
      
      Fixes: 6446b315 ("bpf: add a new API libbpf_num_possible_cpus()")
      Signed-off-by: default avatarTakshak Chahande <ctakshak@fb.com>
      Acked-by: default avatarAndrey Ignatov <rdna@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      56fbc241
  3. 27 Jul, 2019 1 commit
    • Andrii Nakryiko's avatar
      libbpf: fix erroneous multi-closing of BTF FD · 5d01ab7b
      Andrii Nakryiko authored
      Libbpf stores associated BTF FD per each instance of bpf_program. When
      program is unloaded, that FD is closed. This is wrong, because leads to
      a race and possibly closing of unrelated files, if application
      simultaneously opens new files while bpf_programs are unloaded.
      
      It's also unnecessary, because struct btf "owns" that FD, and
      btf__free(), called from bpf_object__close() will close it. Thus the fix
      is to never have per-program BTF FD and fetch it from obj->btf, when
      necessary.
      
      Fixes: 2993e051 ("tools/bpf: add support to read .BTF.ext sections")
      Reported-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      5d01ab7b
  4. 26 Jul, 2019 10 commits
  5. 25 Jul, 2019 18 commits
  6. 24 Jul, 2019 4 commits