1. 09 Feb, 2022 11 commits
  2. 08 Feb, 2022 16 commits
  3. 07 Feb, 2022 6 commits
  4. 05 Feb, 2022 1 commit
    • Yonghong Song's avatar
      libbpf: Fix build issue with llvm-readelf · 0908a66a
      Yonghong Song authored
      There are cases where clang compiler is packaged in a way
      readelf is a symbolic link to llvm-readelf. In such cases,
      llvm-readelf will be used instead of default binutils readelf,
      and the following error will appear during libbpf build:
      
        Warning: Num of global symbols in
         /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/sharedobjs/libbpf-in.o (367)
         does NOT match with num of versioned symbols in
         /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.so libbpf.map (383).
         Please make sure all LIBBPF_API symbols are versioned in libbpf.map.
        --- /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_global_syms.tmp ...
        +++ /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_versioned_syms.tmp ...
        @@ -324,6 +324,22 @@
         btf__str_by_offset
         btf__type_by_id
         btf__type_cnt
        +LIBBPF_0.0.1
        +LIBBPF_0.0.2
        +LIBBPF_0.0.3
        +LIBBPF_0.0.4
        +LIBBPF_0.0.5
        +LIBBPF_0.0.6
        +LIBBPF_0.0.7
        +LIBBPF_0.0.8
        +LIBBPF_0.0.9
        +LIBBPF_0.1.0
        +LIBBPF_0.2.0
        +LIBBPF_0.3.0
        +LIBBPF_0.4.0
        +LIBBPF_0.5.0
        +LIBBPF_0.6.0
        +LIBBPF_0.7.0
         libbpf_attach_type_by_name
         libbpf_find_kernel_btf
         libbpf_find_vmlinux_btf_id
        make[2]: *** [Makefile:184: check_abi] Error 1
        make[1]: *** [Makefile:140: all] Error 2
      
      The above failure is due to different printouts for some ABS
      versioned symbols. For example, with the same libbpf.so,
        $ /bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
           134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.5.0
           202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.6.0
           ...
        $ /opt/llvm/bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
           134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.5.0@@LIBBPF_0.5.0
           202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.6.0@@LIBBPF_0.6.0
           ...
      The binutils readelf doesn't print out the symbol LIBBPF_* version and llvm-readelf does.
      Such a difference caused libbpf build failure with llvm-readelf.
      
      The proposed fix filters out all ABS symbols as they are not part of the comparison.
      This works for both binutils readelf and llvm-readelf.
      Reported-by: default avatarDelyan Kratunov <delyank@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20220204214355.502108-1-yhs@fb.com
      0908a66a
  5. 04 Feb, 2022 4 commits
  6. 03 Feb, 2022 2 commits
    • Yonghong Song's avatar
      selftests/bpf: Add a selftest for invalid func btf with btf decl_tag · cf1a4cbc
      Yonghong Song authored
      Added a selftest similar to [1] which exposed a kernel bug.
      Without the fix in the previous patch, the similar kasan error will appear.
      
        [1] https://lore.kernel.org/bpf/0000000000009b6eaa05d71a8c06@google.com/Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Link: https://lore.kernel.org/bpf/20220203191732.742285-1-yhs@fb.com
      cf1a4cbc
    • Yonghong Song's avatar
      bpf: Fix a btf decl_tag bug when tagging a function · d7e7b42f
      Yonghong Song authored
      syzbot reported a btf decl_tag bug with stack trace below:
      
        general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
        KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
        CPU: 0 PID: 3592 Comm: syz-executor914 Not tainted 5.16.0-syzkaller-11424-gb7892f7d #0
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
        RIP: 0010:btf_type_vlen include/linux/btf.h:231 [inline]
        RIP: 0010:btf_decl_tag_resolve+0x83e/0xaa0 kernel/bpf/btf.c:3910
        ...
        Call Trace:
         <TASK>
         btf_resolve+0x251/0x1020 kernel/bpf/btf.c:4198
         btf_check_all_types kernel/bpf/btf.c:4239 [inline]
         btf_parse_type_sec kernel/bpf/btf.c:4280 [inline]
         btf_parse kernel/bpf/btf.c:4513 [inline]
         btf_new_fd+0x19fe/0x2370 kernel/bpf/btf.c:6047
         bpf_btf_load kernel/bpf/syscall.c:4039 [inline]
         __sys_bpf+0x1cbb/0x5970 kernel/bpf/syscall.c:4679
         __do_sys_bpf kernel/bpf/syscall.c:4738 [inline]
         __se_sys_bpf kernel/bpf/syscall.c:4736 [inline]
         __x64_sys_bpf+0x75/0xb0 kernel/bpf/syscall.c:4736
         do_syscall_x64 arch/x86/entry/common.c:50 [inline]
         do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
         entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      The kasan error is triggered with an illegal BTF like below:
         type 0: void
         type 1: int
         type 2: decl_tag to func type 3
         type 3: func to func_proto type 8
      The total number of types is 4 and the type 3 is illegal
      since its func_proto type is out of range.
      
      Currently, the target type of decl_tag can be struct/union, var or func.
      Both struct/union and var implemented their own 'resolve' callback functions
      and hence handled properly in kernel.
      But func type doesn't have 'resolve' callback function. When
      btf_decl_tag_resolve() tries to check func type, it tries to get
      vlen of its func_proto type, which triggered the above kasan error.
      
      To fix the issue, btf_decl_tag_resolve() needs to do btf_func_check()
      before trying to accessing func_proto type.
      In the current implementation, func type is checked with
      btf_func_check() in the main checking function btf_check_all_types().
      To fix the above kasan issue, let us implement 'resolve' callback
      func type properly. The 'resolve' callback will be also called
      in btf_check_all_types() for func types.
      
      Fixes: b5ea834d ("bpf: Support for new btf kind BTF_KIND_TAG")
      Reported-by: syzbot+53619be9444215e785ed@syzkaller.appspotmail.com
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Link: https://lore.kernel.org/bpf/20220203191727.741862-1-yhs@fb.com
      d7e7b42f