Skip to content
Snippets Groups Projects
  1. Aug 02, 2020
  2. Jan 21, 2020
  3. Oct 30, 2019
  4. Sep 25, 2019
  5. Sep 16, 2019
  6. Sep 03, 2019
  7. Apr 12, 2019
    • Andrey Ignatov's avatar
      selftests/bpf: C based test for sysctl and strtoX · 7568f4cb
      Andrey Ignatov authored
      
      Add C based test for a few bpf_sysctl_* helpers and bpf_strtoul.
      
      Make sure that sysctl can be identified by name and that multiple
      integers can be parsed from sysctl value with bpf_strtoul.
      
      net/ipv4/tcp_mem is chosen as a testing sysctl, it contains 3 unsigned
      longs, they all are parsed and compared (val[0] < val[1] < val[2]).
      
      Example of output:
        # ./test_sysctl
        ...
        Test case: C prog: deny all writes .. [PASS]
        Test case: C prog: deny access by name .. [PASS]
        Test case: C prog: read tcp_mem .. [PASS]
        Summary: 39 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      7568f4cb
    • Andrey Ignatov's avatar
      selftests/bpf: Test bpf_strtol and bpf_strtoul helpers · 8549ddc8
      Andrey Ignatov authored
      
      Test that bpf_strtol and  bpf_strtoul helpers can be used to convert
      provided buffer to long or unsigned long correspondingly and return both
      correct result and number of consumed bytes, or proper errno.
      
      Example of output:
        # ./test_sysctl
        ..
        Test case: bpf_strtoul one number string .. [PASS]
        Test case: bpf_strtoul multi number string .. [PASS]
        Test case: bpf_strtoul buf_len = 0, reject .. [PASS]
        Test case: bpf_strtoul supported base, ok .. [PASS]
        Test case: bpf_strtoul unsupported base, EINVAL .. [PASS]
        Test case: bpf_strtoul buf with spaces only, EINVAL .. [PASS]
        Test case: bpf_strtoul negative number, EINVAL .. [PASS]
        Test case: bpf_strtol negative number, ok .. [PASS]
        Test case: bpf_strtol hex number, ok .. [PASS]
        Test case: bpf_strtol max long .. [PASS]
        Test case: bpf_strtol overflow, ERANGE .. [PASS]
        Summary: 36 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      8549ddc8
    • Andrey Ignatov's avatar
      selftests/bpf: Test file_pos field in bpf_sysctl ctx · 9a1027e5
      Andrey Ignatov authored
      
      Test access to file_pos field of bpf_sysctl context, both read (incl.
      narrow read) and write.
      
        # ./test_sysctl
        ...
        Test case: ctx:file_pos sysctl:read read ok .. [PASS]
        Test case: ctx:file_pos sysctl:read read ok narrow .. [PASS]
        Test case: ctx:file_pos sysctl:read write ok .. [PASS]
        ...
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      9a1027e5
    • Andrey Ignatov's avatar
      selftests/bpf: Test bpf_sysctl_{get,set}_new_value helpers · 786047dd
      Andrey Ignatov authored
      
      Test that new value provided by user space on sysctl write can be read
      by bpf_sysctl_get_new_value and overridden by bpf_sysctl_set_new_value.
      
        # ./test_sysctl
        ...
        Test case: sysctl_get_new_value sysctl:read EINVAL .. [PASS]
        Test case: sysctl_get_new_value sysctl:write ok .. [PASS]
        Test case: sysctl_get_new_value sysctl:write ok long .. [PASS]
        Test case: sysctl_get_new_value sysctl:write E2BIG .. [PASS]
        Test case: sysctl_set_new_value sysctl:read EINVAL .. [PASS]
        Test case: sysctl_set_new_value sysctl:write ok .. [PASS]
        Summary: 22 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      786047dd
    • Andrey Ignatov's avatar
      selftests/bpf: Test sysctl_get_current_value helper · 11ff34f7
      Andrey Ignatov authored
      
      Test sysctl_get_current_value on sysctl read and write, buffers with
      enough space and too small buffers to get E2BIG and truncated result,
      etc.
      
        # ./test_sysctl
        ...
        Test case: sysctl_get_current_value sysctl:read ok, gt .. [PASS]
        Test case: sysctl_get_current_value sysctl:read ok, eq .. [PASS]
        Test case: sysctl_get_current_value sysctl:read E2BIG truncated ..  [PASS]
        Test case: sysctl_get_current_value sysctl:read EINVAL .. [PASS]
        Test case: sysctl_get_current_value sysctl:write ok .. [PASS]
        Summary: 16 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      11ff34f7
    • Andrey Ignatov's avatar
      selftests/bpf: Test bpf_sysctl_get_name helper · 6041c67f
      Andrey Ignatov authored
      
      Test w/ and w/o BPF_F_SYSCTL_BASE_NAME, buffers with enough space and
      too small buffers to get E2BIG and truncated result, etc.
      
        # ./test_sysctl
        ...
        Test case: sysctl_get_name sysctl_value:base ok .. [PASS]
        Test case: sysctl_get_name sysctl_value:base E2BIG truncated .. [PASS]
        Test case: sysctl_get_name sysctl:full ok .. [PASS]
        Test case: sysctl_get_name sysctl:full E2BIG truncated .. [PASS]
        Test case: sysctl_get_name sysctl:full E2BIG truncated small .. [PASS]
        Summary: 11 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6041c67f
    • Andrey Ignatov's avatar
      selftests/bpf: Test BPF_CGROUP_SYSCTL · 1f5fa9ab
      Andrey Ignatov authored
      
      Add unit test for BPF_PROG_TYPE_CGROUP_SYSCTL program type.
      
      Test that program can allow/deny access.
      Test both valid and invalid accesses to ctx->write.
      
      Example of output:
        # ./test_sysctl
        Test case: sysctl wrong attach_type .. [PASS]
        Test case: sysctl:read allow all .. [PASS]
        Test case: sysctl:read deny all .. [PASS]
        Test case: ctx:write sysctl:read read ok .. [PASS]
        Test case: ctx:write sysctl:write read ok .. [PASS]
        Test case: ctx:write sysctl:read write reject .. [PASS]
        Summary: 6 PASSED, 0 FAILED
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      1f5fa9ab
Loading