1. 20 Nov, 2018 5 commits
    • Yonghong Song's avatar
      bpf: Introduce bpf_func_info · 838e9690
      Yonghong Song authored
      This patch added interface to load a program with the following
      additional information:
         . prog_btf_fd
         . func_info, func_info_rec_size and func_info_cnt
      where func_info will provide function range and type_id
      corresponding to each function.
      
      The func_info_rec_size is introduced in the UAPI to specify
      struct bpf_func_info size passed from user space. This
      intends to make bpf_func_info structure growable in the future.
      If the kernel gets a different bpf_func_info size from userspace,
      it will try to handle user request with part of bpf_func_info
      it can understand. In this patch, kernel can understand
        struct bpf_func_info {
             __u32   insn_offset;
             __u32   type_id;
        };
      If user passed a bpf func_info record size of 16 bytes, the
      kernel can still handle part of records with the above definition.
      
      If verifier agrees with function range provided by the user,
      the bpf_prog ksym for each function will use the func name
      provided in the type_id, which is supposed to provide better
      encoding as it is not limited by 16 bytes program name
      limitation and this is better for bpf program which contains
      multiple subprograms.
      
      The bpf_prog_info interface is also extended to
      return btf_id, func_info, func_info_rec_size and func_info_cnt
      to userspace, so userspace can print out the function prototype
      for each xlated function. The insn_offset in the returned
      func_info corresponds to the insn offset for xlated functions.
      With other jit related fields in bpf_prog_info, userspace can also
      print out function prototypes for each jited function.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      838e9690
    • Martin KaFai Lau's avatar
      tools/bpf: Add tests for BTF_KIND_FUNC_PROTO and BTF_KIND_FUNC · 78a2540e
      Martin KaFai Lau authored
      This patch adds unit tests for BTF_KIND_FUNC_PROTO and
      BTF_KIND_FUNC to test_btf.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      78a2540e
    • Martin KaFai Lau's avatar
      tools/bpf: Sync kernel btf.h header · 781e775e
      Martin KaFai Lau authored
      The kernel uapi btf.h is synced to the tools directory.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      781e775e
    • Martin KaFai Lau's avatar
      bpf: btf: Add BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO · 2667a262
      Martin KaFai Lau authored
      This patch adds BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO
      to support the function debug info.
      
      BTF_KIND_FUNC_PROTO must not have a name (i.e. !t->name_off)
      and it is followed by >= 0 'struct bpf_param' objects to
      describe the function arguments.
      
      The BTF_KIND_FUNC must have a valid name and it must
      refer back to a BTF_KIND_FUNC_PROTO.
      
      The above is the conclusion after the discussion between
      Edward Cree, Alexei, Daniel, Yonghong and Martin.
      
      By combining BTF_KIND_FUNC and BTF_LIND_FUNC_PROTO,
      a complete function signature can be obtained.  It will be
      used in the later patches to learn the function signature of
      a running bpf program.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      2667a262
    • Martin KaFai Lau's avatar
      bpf: btf: Break up btf_type_is_void() · b47a0bd2
      Martin KaFai Lau authored
      This patch breaks up btf_type_is_void() into
      btf_type_is_void() and btf_type_is_fwd().
      
      It also adds btf_type_nosize() to better describe it is
      testing a type has nosize info.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      b47a0bd2
  2. 19 Nov, 2018 6 commits
  3. 17 Nov, 2018 9 commits
  4. 11 Nov, 2018 4 commits
    • Alexei Starovoitov's avatar
      Merge branch 'narrow-loads' · 407be8d0
      Alexei Starovoitov authored
      Andrey Ignatov says:
      
      ====================
      This patch set adds support for narrow loads with offset > 0 to BPF
      verifier.
      
      Patch 1 provides more details and is the main patch in the set.
      Patches 2 and 3 add new test cases to test_verifier and test_sock_addr
      selftests.
      
      v1->v2:
      - fix -Wdeclaration-after-statement warning.
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      407be8d0
    • Andrey Ignatov's avatar
      selftests/bpf: Test narrow loads with off > 0 for bpf_sock_addr · e7605475
      Andrey Ignatov authored
      Add more test cases for context bpf_sock_addr to test narrow loads with
      offset > 0 for ctx->user_ip4 field (__u32):
      * off=1, size=1;
      * off=2, size=1;
      * off=3, size=1;
      * off=2, size=2.
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      e7605475
    • Andrey Ignatov's avatar
      selftests/bpf: Test narrow loads with off > 0 in test_verifier · 6c2afb67
      Andrey Ignatov authored
      Test the following narrow loads in test_verifier for context __sk_buff:
      * off=1, size=1 - ok;
      * off=2, size=1 - ok;
      * off=3, size=1 - ok;
      * off=0, size=2 - ok;
      * off=1, size=2 - fail;
      * off=0, size=2 - ok;
      * off=3, size=2 - fail.
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6c2afb67
    • Andrey Ignatov's avatar
      bpf: Allow narrow loads with offset > 0 · 46f53a65
      Andrey Ignatov authored
      Currently BPF verifier allows narrow loads for a context field only with
      offset zero. E.g. if there is a __u32 field then only the following
      loads are permitted:
        * off=0, size=1 (narrow);
        * off=0, size=2 (narrow);
        * off=0, size=4 (full).
      
      On the other hand LLVM can generate a load with offset different than
      zero that make sense from program logic point of view, but verifier
      doesn't accept it.
      
      E.g. tools/testing/selftests/bpf/sendmsg4_prog.c has code:
      
        #define DST_IP4			0xC0A801FEU /* 192.168.1.254 */
        ...
        	if ((ctx->user_ip4 >> 24) == (bpf_htonl(DST_IP4) >> 24) &&
      
      where ctx is struct bpf_sock_addr.
      
      Some versions of LLVM can produce the following byte code for it:
      
             8:       71 12 07 00 00 00 00 00         r2 = *(u8 *)(r1 + 7)
             9:       67 02 00 00 18 00 00 00         r2 <<= 24
            10:       18 03 00 00 00 00 00 fe 00 00 00 00 00 00 00 00         r3 = 4261412864 ll
            12:       5d 32 07 00 00 00 00 00         if r2 != r3 goto +7 <LBB0_6>
      
      where `*(u8 *)(r1 + 7)` means narrow load for ctx->user_ip4 with size=1
      and offset=3 (7 - sizeof(ctx->user_family) = 3). This load is currently
      rejected by verifier.
      
      Verifier code that rejects such loads is in bpf_ctx_narrow_access_ok()
      what means any is_valid_access implementation, that uses the function,
      works this way, e.g. bpf_skb_is_valid_access() for __sk_buff or
      sock_addr_is_valid_access() for bpf_sock_addr.
      
      The patch makes such loads supported. Offset can be in [0; size_default)
      but has to be multiple of load size. E.g. for __u32 field the following
      loads are supported now:
        * off=0, size=1 (narrow);
        * off=1, size=1 (narrow);
        * off=2, size=1 (narrow);
        * off=3, size=1 (narrow);
        * off=0, size=2 (narrow);
        * off=2, size=2 (narrow);
        * off=0, size=4 (full).
      Reported-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      46f53a65
  5. 10 Nov, 2018 16 commits