1. 17 8月, 2021 5 次提交
  2. 14 8月, 2021 1 次提交
    • H
      libbpf: Support weak typed ksyms. · 2211c825
      Hao Luo 提交于
      Currently weak typeless ksyms have default value zero, when they don't
      exist in the kernel. However, weak typed ksyms are rejected by libbpf
      if they can not be resolved. This means that if a bpf object contains
      the declaration of a nonexistent weak typed ksym, it will be rejected
      even if there is no program that references the symbol.
      
      Nonexistent weak typed ksyms can also default to zero just like
      typeless ones. This allows programs that access weak typed ksyms to be
      accepted by verifier, if the accesses are guarded. For example,
      
      extern const int bpf_link_fops3 __ksym __weak;
      
      /* then in BPF program */
      
      if (&bpf_link_fops3) {
         /* use bpf_link_fops3 */
      }
      
      If actual use of nonexistent typed ksym is not guarded properly,
      verifier would see that register is not PTR_TO_BTF_ID and wouldn't
      allow to use it for direct memory reads or passing it to BPF helpers.
      Signed-off-by: NHao Luo <haoluo@google.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210812003819.2439037-1-haoluo@google.com
      2211c825
  3. 07 8月, 2021 2 次提交
  4. 31 7月, 2021 1 次提交
  5. 30 7月, 2021 4 次提交
  6. 28 7月, 2021 2 次提交
  7. 27 7月, 2021 4 次提交
  8. 24 7月, 2021 1 次提交
  9. 23 7月, 2021 3 次提交
  10. 21 7月, 2021 2 次提交
  11. 20 7月, 2021 1 次提交
  12. 17 7月, 2021 6 次提交
  13. 16 7月, 2021 2 次提交
  14. 13 7月, 2021 1 次提交
    • M
      libbpf: Fix reuse of pinned map on older kernel · 97eb3138
      Martynas Pumputis 提交于
      When loading a BPF program with a pinned map, the loader checks whether
      the pinned map can be reused, i.e. their properties match. To derive
      such of the pinned map, the loader invokes BPF_OBJ_GET_INFO_BY_FD and
      then does the comparison.
      
      Unfortunately, on < 4.12 kernels the BPF_OBJ_GET_INFO_BY_FD is not
      available, so loading the program fails with the following error:
      
      	libbpf: failed to get map info for map FD 5: Invalid argument
      	libbpf: couldn't reuse pinned map at
      		'/sys/fs/bpf/tc/globals/cilium_call_policy': parameter
      		mismatch"
      	libbpf: map 'cilium_call_policy': error reusing pinned map
      	libbpf: map 'cilium_call_policy': failed to create:
      		Invalid argument(-22)
      	libbpf: failed to load object 'bpf_overlay.o'
      
      To fix this, fallback to derivation of the map properties via
      /proc/$PID/fdinfo/$MAP_FD if BPF_OBJ_GET_INFO_BY_FD fails with EINVAL,
      which can be used as an indicator that the kernel doesn't support
      the latter.
      Signed-off-by: NMartynas Pumputis <m@lambda.lt>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20210712125552.58705-1-m@lambda.lt
      97eb3138
  15. 07 7月, 2021 1 次提交
  16. 22 6月, 2021 2 次提交
    • K
      libbpf: Switch to void * casting in netlink helpers · ee62a5c6
      Kumar Kartikeya Dwivedi 提交于
      Netlink helpers I added in 8bbb77b7 ("libbpf: Add various netlink
      helpers") used char * casts everywhere, and there were a few more that
      existed from before.
      
      Convert all of them to void * cast, as it is treated equivalently by
      clang/gcc for the purposes of pointer arithmetic and to follow the
      convention elsewhere in the kernel/libbpf.
      Signed-off-by: NKumar Kartikeya Dwivedi <memxor@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20210619041454.417577-2-memxor@gmail.com
      ee62a5c6
    • K
      libbpf: Add request buffer type for netlink messages · 0ae64fb6
      Kumar Kartikeya Dwivedi 提交于
      Coverity complains about OOB writes to nlmsghdr. There is no OOB as we
      write to the trailing buffer, but static analyzers and compilers may
      rightfully be confused as the nlmsghdr pointer has subobject provenance
      (and hence subobject bounds).
      
      Fix this by using an explicit request structure containing the nlmsghdr,
      struct tcmsg/ifinfomsg, and attribute buffer.
      
      Also switch nh_tail (renamed to req_tail) to cast req * to char * so
      that it can be understood as arithmetic on pointer to the representation
      array (hence having same bound as request structure), which should
      further appease analyzers.
      
      As a bonus, callers don't have to pass sizeof(req) all the time now, as
      size is implicitly obtained using the pointer. While at it, also reduce
      the size of attribute buffer to 128 bytes (132 for ifinfomsg using
      functions due to the padding).
      
      Summary of problem:
      
        Even though C standard allows interconvertibility of pointer to first
        member and pointer to struct, for the purposes of alias analysis it
        would still consider the first as having pointer value "pointer to T"
        where T is type of first member hence having subobject bounds,
        allowing analyzers within reason to complain when object is accessed
        beyond the size of pointed to object.
      
        The only exception to this rule may be when a char * is formed to a
        member subobject. It is not possible for the compiler to be able to
        tell the intent of the programmer that it is a pointer to member
        object or the underlying representation array of the containing
        object, so such diagnosis is suppressed.
      
      Fixes: 715c5ce4 ("libbpf: Add low level TC-BPF management API")
      Signed-off-by: NKumar Kartikeya Dwivedi <memxor@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20210619041454.417577-1-memxor@gmail.com
      0ae64fb6
  17. 21 6月, 2021 1 次提交
  18. 19 6月, 2021 1 次提交
    • G
      bpf: Add documentation for libbpf including API autogen · f42cfb46
      Grant Seltzer 提交于
      This patch is meant to start the initiative to document libbpf.
      It includes .rst files which are text documentation describing building,
      API naming convention, as well as an index to generated API documentation.
      
      In this approach the generated API documentation is enabled by the kernels
      existing kernel documentation system which uses sphinx. The resulting docs
      would then be synced to kernel.org/doc
      
      You can test this by running `make htmldocs` and serving the html in
      Documentation/output. Since libbpf does not yet have comments in kernel
      doc format, see kernel.org/doc/html/latest/doc-guide/kernel-doc.html for
      an example so you can test this.
      
      The advantage of this approach is to use the existing sphinx
      infrastructure that the kernel has, and have libbpf docs in
      the same place as everything else.
      
      The current plan is to have the libbpf mirror sync the generated docs
      and version them based on the libbpf releases which are cut on github.
      
      This patch includes the addition of libbpf_api.rst which pulls comment
      documentation from header files in libbpf under tools/lib/bpf/. The comment
      docs would be of the standard kernel doc format.
      Signed-off-by: NGrant Seltzer <grantseltzer@gmail.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20210618140459.9887-2-grantseltzer@gmail.com
      f42cfb46