1. 25 4月, 2018 1 次提交
  2. 20 4月, 2018 1 次提交
    • M
      bpf: btf: Add BTF tests · c0fa1b6c
      Martin KaFai Lau 提交于
      This patch tests the BTF loading, map_create with BTF
      and the changes in libbpf.
      
      -r: Raw tests that test raw crafted BTF data
      -f: Test LLVM compiled bpf prog with BTF data
      -g: Test BPF_OBJ_GET_INFO_BY_FD for btf_fd
      -p: Test pretty print
      
      The tools/testing/selftests/bpf/Makefile will probe
      for BTF support in llc and pahole before generating
      debug info (-g) and convert them to BTF.  You can supply
      the BTF supported binary through the following make variables:
      LLC, BTF_PAHOLE and LLVM_OBJCOPY.
      
      LLC: The lastest llc with -mattr=dwarfris support for the bpf target.
           It is only in the master of the llvm repo for now.
      BTF_PAHOLE: The modified pahole with BTF support:
      	    https://github.com/iamkafai/pahole/tree/btf
      	    To add a BTF section: "pahole -J bpf_prog.o"
      LLVM_OBJCOPY: Any llvm-objcopy should do
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NAlexei Starovoitov <ast@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      c0fa1b6c
  3. 19 4月, 2018 2 次提交
  4. 18 4月, 2018 1 次提交
  5. 17 4月, 2018 2 次提交
  6. 16 4月, 2018 1 次提交
  7. 13 4月, 2018 3 次提交
  8. 12 4月, 2018 6 次提交
  9. 10 4月, 2018 1 次提交
  10. 05 4月, 2018 2 次提交
  11. 03 4月, 2018 2 次提交
  12. 31 3月, 2018 5 次提交
    • A
      selftests/bpf: Selftest for sys_bind post-hooks. · 1d436885
      Andrey Ignatov 提交于
      Add selftest for attach types `BPF_CGROUP_INET4_POST_BIND` and
      `BPF_CGROUP_INET6_POST_BIND`.
      
      The main things tested are:
      * prog load behaves as expected (valid/invalid accesses in prog);
      * prog attach behaves as expected (load- vs attach-time attach types);
      * `BPF_CGROUP_INET_SOCK_CREATE` can be attached in a backward compatible
        way;
      * post-hooks return expected result and errno.
      
      Example:
        # ./test_sock
        Test case: bind4 load with invalid access: src_ip6 .. [PASS]
        Test case: bind4 load with invalid access: mark .. [PASS]
        Test case: bind6 load with invalid access: src_ip4 .. [PASS]
        Test case: sock_create load with invalid access: src_port .. [PASS]
        Test case: sock_create load w/o expected_attach_type (compat mode) ..
        [PASS]
        Test case: sock_create load w/ expected_attach_type .. [PASS]
        Test case: attach type mismatch bind4 vs bind6 .. [PASS]
        Test case: attach type mismatch bind6 vs bind4 .. [PASS]
        Test case: attach type mismatch default vs bind4 .. [PASS]
        Test case: attach type mismatch bind6 vs sock_create .. [PASS]
        Test case: bind4 reject all .. [PASS]
        Test case: bind6 reject all .. [PASS]
        Test case: bind6 deny specific IP & port .. [PASS]
        Test case: bind4 allow specific IP & port .. [PASS]
        Test case: bind4 allow all .. [PASS]
        Test case: bind6 allow all .. [PASS]
        Summary: 16 PASSED, 0 FAILED
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      1d436885
    • A
      selftests/bpf: Selftest for sys_connect hooks · 622adafb
      Andrey Ignatov 提交于
      Add selftest for BPF_CGROUP_INET4_CONNECT and BPF_CGROUP_INET6_CONNECT
      attach types.
      
      Try to connect(2) to specified IP:port and test that:
      * remote IP:port pair is overridden;
      * local end of connection is bound to specified IP.
      
      All combinations of IPv4/IPv6 and TCP/UDP are tested.
      
      Example:
        # tcpdump -pn -i lo -w connect.pcap 2>/dev/null &
        [1] 478
        # strace -qqf -e connect -o connect.trace ./test_sock_addr.sh
        Wait for testing IPv4/IPv6 to become available ... OK
        Load bind4 with invalid type (can pollute stderr) ... REJECTED
        Load bind4 with valid type ... OK
        Attach bind4 with invalid type ... REJECTED
        Attach bind4 with valid type ... OK
        Load connect4 with invalid type (can pollute stderr) libbpf: load bpf \
          program failed: Permission denied
        libbpf: -- BEGIN DUMP LOG ---
        libbpf:
        0: (b7) r2 = 23569
        1: (63) *(u32 *)(r1 +24) = r2
        2: (b7) r2 = 16777343
        3: (63) *(u32 *)(r1 +4) = r2
        invalid bpf_context access off=4 size=4
        [ 1518.404609] random: crng init done
      
        libbpf: -- END LOG --
        libbpf: failed to load program 'cgroup/connect4'
        libbpf: failed to load object './connect4_prog.o'
        ... REJECTED
        Load connect4 with valid type ... OK
        Attach connect4 with invalid type ... REJECTED
        Attach connect4 with valid type ... OK
        Test case #1 (IPv4/TCP):
                Requested: bind(192.168.1.254, 4040) ..
                   Actual: bind(127.0.0.1, 4444)
                Requested: connect(192.168.1.254, 4040) from (*, *) ..
                   Actual: connect(127.0.0.1, 4444) from (127.0.0.4, 56068)
        Test case #2 (IPv4/UDP):
                Requested: bind(192.168.1.254, 4040) ..
                   Actual: bind(127.0.0.1, 4444)
                Requested: connect(192.168.1.254, 4040) from (*, *) ..
                   Actual: connect(127.0.0.1, 4444) from (127.0.0.4, 56447)
        Load bind6 with invalid type (can pollute stderr) ... REJECTED
        Load bind6 with valid type ... OK
        Attach bind6 with invalid type ... REJECTED
        Attach bind6 with valid type ... OK
        Load connect6 with invalid type (can pollute stderr) libbpf: load bpf \
          program failed: Permission denied
        libbpf: -- BEGIN DUMP LOG ---
        libbpf:
        0: (b7) r6 = 0
        1: (63) *(u32 *)(r1 +12) = r6
        invalid bpf_context access off=12 size=4
      
        libbpf: -- END LOG --
        libbpf: failed to load program 'cgroup/connect6'
        libbpf: failed to load object './connect6_prog.o'
        ... REJECTED
        Load connect6 with valid type ... OK
        Attach connect6 with invalid type ... REJECTED
        Attach connect6 with valid type ... OK
        Test case #3 (IPv6/TCP):
                Requested: bind(face:b00c:1234:5678::abcd, 6060) ..
                   Actual: bind(::1, 6666)
                Requested: connect(face:b00c:1234:5678::abcd, 6060) from (*, *)
                   Actual: connect(::1, 6666) from (::6, 37458)
        Test case #4 (IPv6/UDP):
                Requested: bind(face:b00c:1234:5678::abcd, 6060) ..
                   Actual: bind(::1, 6666)
                Requested: connect(face:b00c:1234:5678::abcd, 6060) from (*, *)
                   Actual: connect(::1, 6666) from (::6, 39315)
        ### SUCCESS
        # egrep 'connect\(.*AF_INET' connect.trace | \
        > egrep -vw 'htons\(1025\)' | fold -b -s -w 72
        502   connect(7, {sa_family=AF_INET, sin_port=htons(4040),
        sin_addr=inet_addr("192.168.1.254")}, 128) = 0
        502   connect(8, {sa_family=AF_INET, sin_port=htons(4040),
        sin_addr=inet_addr("192.168.1.254")}, 128) = 0
        502   connect(9, {sa_family=AF_INET6, sin6_port=htons(6060),
        inet_pton(AF_INET6, "face:b00c:1234:5678::abcd", &sin6_addr),
        sin6_flowinfo=0, sin6_scope_id=0}, 128) = 0
        502   connect(10, {sa_family=AF_INET6, sin6_port=htons(6060),
        inet_pton(AF_INET6, "face:b00c:1234:5678::abcd", &sin6_addr),
        sin6_flowinfo=0, sin6_scope_id=0}, 128) = 0
        # fg
        tcpdump -pn -i lo -w connect.pcap 2> /dev/null
        # tcpdump -r connect.pcap -n tcp | cut -c 1-72
        reading from file connect.pcap, link-type EN10MB (Ethernet)
        17:57:40.383533 IP 127.0.0.4.56068 > 127.0.0.1.4444: Flags [S], seq 1333
        17:57:40.383566 IP 127.0.0.1.4444 > 127.0.0.4.56068: Flags [S.], seq 112
        17:57:40.383589 IP 127.0.0.4.56068 > 127.0.0.1.4444: Flags [.], ack 1, w
        17:57:40.384578 IP 127.0.0.1.4444 > 127.0.0.4.56068: Flags [R.], seq 1,
        17:57:40.403327 IP6 ::6.37458 > ::1.6666: Flags [S], seq 406513443, win
        17:57:40.403357 IP6 ::1.6666 > ::6.37458: Flags [S.], seq 2448389240, ac
        17:57:40.403376 IP6 ::6.37458 > ::1.6666: Flags [.], ack 1, win 342, opt
        17:57:40.404263 IP6 ::1.6666 > ::6.37458: Flags [R.], seq 1, ack 1, win
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      622adafb
    • A
      selftests/bpf: Selftest for sys_bind hooks · e50b0a6f
      Andrey Ignatov 提交于
      Add selftest to work with bpf_sock_addr context from
      `BPF_PROG_TYPE_CGROUP_SOCK_ADDR` programs.
      
      Try to bind(2) on IP:port and apply:
      * loads to make sure context can be read correctly, including narrow
        loads (byte, half) for IP and full-size loads (word) for all fields;
      * stores to those fields allowed by verifier.
      
      All combination from IPv4/IPv6 and TCP/UDP are tested.
      
      Both scenarios are tested:
      * valid programs can be loaded and attached;
      * invalid programs can be neither loaded nor attached.
      
      Test passes when expected data can be read from context in the
      BPF-program, and after the call to bind(2) socket is bound to IP:port
      pair that was written by BPF-program to the context.
      
      Example:
        # ./test_sock_addr
        Attached bind4 program.
        Test case #1 (IPv4/TCP):
                Requested: bind(192.168.1.254, 4040) ..
                   Actual: bind(127.0.0.1, 4444)
        Test case #2 (IPv4/UDP):
                Requested: bind(192.168.1.254, 4040) ..
                   Actual: bind(127.0.0.1, 4444)
        Attached bind6 program.
        Test case #3 (IPv6/TCP):
                Requested: bind(face:b00c:1234:5678::abcd, 6060) ..
                   Actual: bind(::1, 6666)
        Test case #4 (IPv6/UDP):
                Requested: bind(face:b00c:1234:5678::abcd, 6060) ..
                   Actual: bind(::1, 6666)
        ### SUCCESS
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      e50b0a6f
    • L
      tc-testing: Add newline when writing test case files · c0b6edef
      Lucas Bates 提交于
      When using the -i feature to generate random ID numbers for test
      cases in tdc, the function that writes the JSON to file doesn't
      add a newline character to the end of the file, so we have to
      add our own.
      Signed-off-by: NLucas Bates <lucasb@mojatatu.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c0b6edef
    • R
      tc-testing: add connmark action tests · 1dad0f9f
      Roman Mashak 提交于
      Signed-off-by: NRoman Mashak <mrv@mojatatu.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1dad0f9f
  13. 29 3月, 2018 1 次提交
  14. 27 3月, 2018 2 次提交
    • L
      tc-testing: Correct compound statements for namespace execution · cd464197
      Lucas Bates 提交于
      If tdc is executing test cases inside a namespace, only the
      first command in a compound statement will be executed inside
      the namespace by tdc. As a result, the subsequent commands
      are not executed inside the namespace and the test will fail.
      
      Example:
      
      for i in {x..y}; do args="foo"; done && tc actions add $args
      
      The namespace execution feature will prepend 'ip netns exec'
      to the command:
      
      ip netns exec tcut for i in {x..y}; do args="foo"; done && \
        tc actions add $args
      
      So the actual tc command is not parsed by the shell as being
      part of the namespace execution.
      
      Enclosing these compound statements inside a bash invocation
      with proper escape characters resolves the problem by creating
      a subshell inside the namespace.
      Signed-off-by: NLucas Bates <lucasb@mojatatu.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      cd464197
    • M
      selftests: Print the test we're running to /dev/kmsg · 88893cf7
      Michael Ellerman 提交于
      Some tests cause the kernel to print things to the kernel log
      buffer (ie. printk), in particular oops and warnings etc. However when
      running all the tests in succession it's not always obvious which
      test(s) caused the kernel to print something.
      
      We can narrow it down by printing which test directory we're running
      in to /dev/kmsg, if it's writable.
      
      Example output:
      
        [  170.149149] kselftest: Running tests in powerpc
        [  305.300132] kworker/dying (71) used greatest stack depth: 7776 bytes
                       left
        [  808.915456] kselftest: Running tests in pstore
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: NShuah Khan <shuahkh@osg.samsung.com>
      88893cf7
  15. 26 3月, 2018 1 次提交
  16. 24 3月, 2018 4 次提交
  17. 23 3月, 2018 1 次提交
  18. 22 3月, 2018 2 次提交
  19. 20 3月, 2018 2 次提交
    • L
      test_firmware: modify custom fallback tests to use unique files · 9952db75
      Luis R. Rodriguez 提交于
      Users of the custom firmware fallback interface is are not supposed to
      use the firmware cache interface, this can happen if for instance the
      one of the APIs which use the firmware cache is used first with one
      firmware file and then the request_firmware_nowait(uevent=false) API
      is used with the same file.
      
      We'll soon become strict about this on the firmware interface to reject
      such calls later, so correct the test scripts to avoid such uses as well.
      We address this on the tests scripts by simply using unique names when
      testing the custom fallback interface.
      Signed-off-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9952db75
    • L
      test_firmware: test three firmware kernel configs using a proc knob · b3cf21fa
      Luis R. Rodriguez 提交于
      Since we now have knobs to twiddle what used to be set on kernel
      configurations we can build one base kernel configuration and modify
      behaviour to mimic such kernel configurations to test them.
      
      Provided you build a kernel with:
      
      CONFIG_TEST_FIRMWARE=y
      CONFIG_FW_LOADER=y
      CONFIG_FW_LOADER_USER_HELPER=y
      CONFIG_IKCONFIG=y
      CONFIG_IKCONFIG_PROC=y
      
      We should now be able test all possible kernel configurations
      when FW_LOADER=y. Note that when FW_LOADER=m we just don't provide
      the built-in functionality of the built-in firmware.
      
      If you're on an old kernel and either don't have /proc/config.gz
      (CONFIG_IKCONFIG_PROC) or haven't enabled CONFIG_FW_LOADER_USER_HELPER
      we cannot run these dynamic tests, so just run both scripts just
      as we used to before making blunt assumptions about your setup
      and requirements exactly as we did before.
      Acked-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b3cf21fa