1. 10 10月, 2018 3 次提交
  2. 03 10月, 2018 6 次提交
    • J
      selftests/bpf: Add C tests for reference tracking · de375f4e
      Joe Stringer 提交于
      Add some tests that demonstrate and test the balanced lookup/free
      nature of socket lookup. Section names that start with "fail" represent
      programs that are expected to fail verification; all others should
      succeed.
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Acked-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      de375f4e
    • J
      selftests/bpf: Add tests for reference tracking · b584ab88
      Joe Stringer 提交于
      reference tracking: leak potential reference
      reference tracking: leak potential reference on stack
      reference tracking: leak potential reference on stack 2
      reference tracking: zero potential reference
      reference tracking: copy and zero potential references
      reference tracking: release reference without check
      reference tracking: release reference
      reference tracking: release reference twice
      reference tracking: release reference twice inside branch
      reference tracking: alloc, check, free in one subbranch
      reference tracking: alloc, check, free in both subbranches
      reference tracking in call: free reference in subprog
      reference tracking in call: free reference in subprog and outside
      reference tracking in call: alloc & leak reference in subprog
      reference tracking in call: alloc in subprog, release outside
      reference tracking in call: sk_ptr leak into caller stack
      reference tracking in call: sk_ptr spill into caller stack
      reference tracking: allow LD_ABS
      reference tracking: forbid LD_ABS while holding reference
      reference tracking: allow LD_IND
      reference tracking: forbid LD_IND while holding reference
      reference tracking: check reference or tail call
      reference tracking: release reference then tail call
      reference tracking: leak possible reference over tail call
      reference tracking: leak checked reference over tail call
      reference tracking: mangle and release sock_or_null
      reference tracking: mangle and release sock
      reference tracking: access member
      reference tracking: write to member
      reference tracking: invalid 64-bit access of member
      reference tracking: access after release
      reference tracking: direct access for lookup
      unpriv: spill/fill of different pointers stx - ctx and sock
      unpriv: spill/fill of different pointers stx - leak sock
      unpriv: spill/fill of different pointers stx - sock and ctx (read)
      unpriv: spill/fill of different pointers stx - sock and ctx (write)
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      b584ab88
    • J
      selftests/bpf: Generalize dummy program types · 0c586079
      Joe Stringer 提交于
      Don't hardcode the dummy program types to SOCKET_FILTER type, as this
      prevents testing bpf_tail_call in conjunction with other program types.
      Instead, use the program type specified in the test case.
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      0c586079
    • J
      bpf: Add helper to retrieve socket in BPF · 6acc9b43
      Joe Stringer 提交于
      This patch adds new BPF helper functions, bpf_sk_lookup_tcp() and
      bpf_sk_lookup_udp() which allows BPF programs to find out if there is a
      socket listening on this host, and returns a socket pointer which the
      BPF program can then access to determine, for instance, whether to
      forward or drop traffic. bpf_sk_lookup_xxx() may take a reference on the
      socket, so when a BPF program makes use of this function, it must
      subsequently pass the returned pointer into the newly added sk_release()
      to return the reference.
      
      By way of example, the following pseudocode would filter inbound
      connections at XDP if there is no corresponding service listening for
      the traffic:
      
        struct bpf_sock_tuple tuple;
        struct bpf_sock_ops *sk;
      
        populate_tuple(ctx, &tuple); // Extract the 5tuple from the packet
        sk = bpf_sk_lookup_tcp(ctx, &tuple, sizeof tuple, netns, 0);
        if (!sk) {
          // Couldn't find a socket listening for this traffic. Drop.
          return TC_ACT_SHOT;
        }
        bpf_sk_release(sk, 0);
        return TC_ACT_OK;
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Acked-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      6acc9b43
    • J
      bpf: Reuse canonical string formatter for ctx errs · 9d2be44a
      Joe Stringer 提交于
      The array "reg_type_str" provides canonical formatting of register
      types, however a couple of places would previously check whether a
      register represented the context and write the name "context" directly.
      An upcoming commit will add another pointer type to these statements, so
      to provide more accurate error messages in the verifier, update these
      error messages to use "reg_type_str" instead.
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      9d2be44a
    • J
      bpf: Simplify ptr_min_max_vals adjustment · aad2eeaf
      Joe Stringer 提交于
      An upcoming commit will add another two pointer types that need very
      similar behaviour, so generalise this function now.
      Signed-off-by: NJoe Stringer <joe@wand.net.nz>
      Acked-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      aad2eeaf
  3. 01 10月, 2018 3 次提交
    • R
      selftests/bpf: cgroup local storage-based network counters · 371e4fcc
      Roman Gushchin 提交于
      This commit adds a bpf kselftest, which demonstrates how percpu
      and shared cgroup local storage can be used for efficient lookup-free
      network accounting.
      
      Cgroup local storage provides generic memory area with a very efficient
      lookup free access. To avoid expensive atomic operations for each
      packet, per-cpu cgroup local storage is used. Each packet is initially
      charged to a per-cpu counter, and only if the counter reaches certain
      value (32 in this case), the charge is moved into the global atomic
      counter. This allows to amortize atomic operations, keeping reasonable
      accuracy.
      
      The test also implements a naive network traffic throttling, mostly to
      demonstrate the possibility of bpf cgroup--based network bandwidth
      control.
      
      Expected output:
        ./test_netcnt
        test_netcnt:PASS
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      371e4fcc
    • R
      selftests/bpf: extend the storage test to test per-cpu cgroup storage · 919646d2
      Roman Gushchin 提交于
      This test extends the cgroup storage test to use per-cpu flavor
      of the cgroup storage as well.
      
      The test initializes a per-cpu cgroup storage to some non-zero initial
      value (1000), and then simple bumps a per-cpu counter each time
      the shared counter is atomically incremented. Then it reads all
      per-cpu areas from the userspace side, and checks that the sum
      of values adds to the expected sum.
      
      Expected output:
        $ ./test_cgroup_storage
        test_cgroup_storage:PASS
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      919646d2
    • R
      selftests/bpf: add verifier per-cpu cgroup storage tests · a3c6054f
      Roman Gushchin 提交于
      This commits adds verifier tests covering per-cpu cgroup storage
      functionality. There are 6 new tests, which are exactly the same
      as for shared cgroup storage, but do use per-cpu cgroup storage
      map.
      
      Expected output:
        $ ./test_verifier
        #0/u add+sub+mul OK
        #0/p add+sub+mul OK
        ...
        #286/p invalid cgroup storage access 6 OK
        #287/p valid per-cpu cgroup storage access OK
        #288/p invalid per-cpu cgroup storage access 1 OK
        #289/p invalid per-cpu cgroup storage access 2 OK
        #290/p invalid per-cpu cgroup storage access 3 OK
        #291/p invalid per-cpu cgroup storage access 4 OK
        #292/p invalid per-cpu cgroup storage access 5 OK
        #293/p invalid per-cpu cgroup storage access 6 OK
        #294/p multiple registers share map_lookup_elem result OK
        ...
        #662/p mov64 src == dst OK
        #663/p mov64 src != dst OK
        Summary: 914 PASSED, 0 SKIPPED, 0 FAILED
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      a3c6054f
  4. 28 9月, 2018 2 次提交
  5. 22 9月, 2018 1 次提交
  6. 15 9月, 2018 3 次提交
  7. 07 9月, 2018 2 次提交
  8. 01 9月, 2018 1 次提交
  9. 30 8月, 2018 1 次提交
  10. 29 8月, 2018 2 次提交
  11. 18 8月, 2018 1 次提交
  12. 15 8月, 2018 1 次提交
  13. 13 8月, 2018 2 次提交
    • A
      selftests/bpf: Selftest for bpf_skb_ancestor_cgroup_id · 5ecd8c22
      Andrey Ignatov 提交于
      Add selftests for bpf_skb_ancestor_cgroup_id helper.
      
      test_skb_cgroup_id.sh prepares testing interface and adds tc qdisc and
      filter for it using BPF object compiled from test_skb_cgroup_id_kern.c
      program.
      
      BPF program in test_skb_cgroup_id_kern.c gets ancestor cgroup id using
      the new helper at different levels of cgroup hierarchy that skb belongs
      to, including root level and non-existing level, and saves it to the map
      where the key is the level of corresponding cgroup and the value is its
      id.
      
      To trigger BPF program, user space program test_skb_cgroup_id_user is
      run. It adds itself into testing cgroup and sends UDP datagram to
      link-local multicast address of testing interface. Then it reads cgroup
      ids saved in kernel for different levels from the BPF map and compares
      them with those in user space. They must be equal for every level of
      ancestry.
      
      Example of run:
        # ./test_skb_cgroup_id.sh
        Wait for testing link-local IP to become available ... OK
        Note: 8 bytes struct bpf_elf_map fixup performed due to size mismatch!
        [PASS]
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      5ecd8c22
    • A
      selftests/bpf: Add cgroup id helpers to bpf_helpers.h · 02f6ac74
      Andrey Ignatov 提交于
      Add bpf_skb_cgroup_id and bpf_skb_ancestor_cgroup_id helpers to
      bpf_helpers.h to use them in tests and samples.
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      02f6ac74
  14. 11 8月, 2018 4 次提交
  15. 09 8月, 2018 1 次提交
  16. 03 8月, 2018 4 次提交
    • M
      selftests/bpf: update test_lwt_seg6local.sh according to iproute2 · 8c85cbdf
      Mathieu Xhonneux 提交于
      The shell file for test_lwt_seg6local contains an early iproute2 syntax
      for installing a seg6local End.BPF route. iproute2 support for this
      feature has recently been upstreamed, but with an additional keyword
      required. This patch updates test_lwt_seg6local.sh to the definitive
      iproute2 syntax
      Signed-off-by: NMathieu Xhonneux <m.xhonneux@gmail.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8c85cbdf
    • R
      selftests/bpf: fix a typo in map in map test · 0069fb85
      Roman Gushchin 提交于
      Commit fbeb1603 ("bpf: verifier: MOV64 don't mark dst reg unbounded")
      revealed a typo in commit fb30d4b7 ("bpf: Add tests for map-in-map"):
      BPF_MOV64_REG(BPF_REG_0, 0) was used instead of
      BPF_MOV64_IMM(BPF_REG_0, 0).
      
      I've noticed the problem by running bpf kselftests.
      
      Fixes: fb30d4b7 ("bpf: Add tests for map-in-map")
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Arthur Fabre <afabre@cloudflare.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      0069fb85
    • R
      selftests/bpf: add a cgroup storage test · 68cfa3ac
      Roman Gushchin 提交于
      Implement a test to cover the cgroup storage functionality.
      The test implements a bpf program which drops every second packet
      by using the cgroup storage as a persistent storage.
      
      The test also use the userspace API to check the data
      in the cgroup storage, alter it, and check that the loaded
      and attached bpf program sees the update.
      
      Expected output:
        $ ./test_cgroup_storage
        test_cgroup_storage:PASS
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      68cfa3ac
    • R
      selftests/bpf: add verifier cgroup storage tests · d4c9f573
      Roman Gushchin 提交于
      Add the following verifier tests to cover the cgroup storage
      functionality:
      1) valid access to the cgroup storage
      2) invalid access: use regular hashmap instead of cgroup storage map
      3) invalid access: use invalid map fd
      4) invalid access: try access memory after the cgroup storage
      5) invalid access: try access memory before the cgroup storage
      6) invalid access: call get_local_storage() with non-zero flags
      
      For tests 2)-6) check returned error strings.
      
      Expected output:
        $ ./test_verifier
        #0/u add+sub+mul OK
        #0/p add+sub+mul OK
        #1/u DIV32 by 0, zero check 1 OK
        ...
        #280/p valid cgroup storage access OK
        #281/p invalid cgroup storage access 1 OK
        #282/p invalid cgroup storage access 2 OK
        #283/p invalid per-cgroup storage access 3 OK
        #284/p invalid cgroup storage access 4 OK
        #285/p invalid cgroup storage access 5 OK
        ...
        #649/p pass modified ctx pointer to helper, 2 OK
        #650/p pass modified ctx pointer to helper, 3 OK
        Summary: 901 PASSED, 0 SKIPPED, 0 FAILED
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      d4c9f573
  17. 01 8月, 2018 1 次提交
    • A
      bpf: verifier: MOV64 don't mark dst reg unbounded · fbeb1603
      Arthur Fabre 提交于
      When check_alu_op() handles a BPF_MOV64 between two registers,
      it calls check_reg_arg(DST_OP) on the dst register, marking it
      as unbounded. If the src and dst register are the same, this
      marks the src as unbounded, which can lead to unexpected errors
      for further checks that rely on bounds info. For example:
      
      	BPF_MOV64_IMM(BPF_REG_2, 0),
      	BPF_MOV64_REG(BPF_REG_2, BPF_REG_2),
      	BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_2),
      	BPF_MOV64_IMM(BPF_REG_0, 0),
      	BPF_EXIT_INSN(),
      
      Results in:
      
      	"math between ctx pointer and register with unbounded
      	min value is not allowed"
      
      check_alu_op() now uses check_reg_arg(DST_OP_NO_MARK), and MOVs
      that need to mark the dst register (MOVIMM, MOV32) do so.
      
      Added a test case for MOV64 dst == src, and dst != src.
      Signed-off-by: NArthur Fabre <afabre@cloudflare.com>
      Acked-by: NEdward Cree <ecree@solarflare.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      fbeb1603
  18. 31 7月, 2018 2 次提交