• Daniel Borkmann's avatar
    bpf, selftests: Add test case for mixed cgroup v1/v2 · 43d2b88c
    Daniel Borkmann authored
    Minimal selftest which implements a small BPF policy program to the
    connect(2) hook which rejects TCP connection requests to port 60123
    with EPERM. This is being attached to a non-root cgroup v2 path. The
    test asserts that this works under cgroup v2-only and under a mixed
    cgroup v1/v2 environment where net_classid is set in the former case.
    
    Before fix:
    
      # ./test_progs -t cgroup_v1v2
      test_cgroup_v1v2:PASS:server_fd 0 nsec
      test_cgroup_v1v2:PASS:client_fd 0 nsec
      test_cgroup_v1v2:PASS:cgroup_fd 0 nsec
      test_cgroup_v1v2:PASS:server_fd 0 nsec
      run_test:PASS:skel_open 0 nsec
      run_test:PASS:prog_attach 0 nsec
      test_cgroup_v1v2:PASS:cgroup-v2-only 0 nsec
      run_test:PASS:skel_open 0 nsec
      run_test:PASS:prog_attach 0 nsec
      run_test:PASS:join_classid 0 nsec
      (network_helpers.c:219: errno: None) Unexpected success to connect to server
      test_cgroup_v1v2:FAIL:cgroup-v1v2 unexpected error: -1 (errno 0)
      #27 cgroup_v1v2:FAIL
      Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
    
    After fix:
    
      # ./test_progs -t cgroup_v1v2
      #27 cgroup_v1v2:OK
      Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20210913230759.2313-3-daniel@iogearbox.net
    43d2b88c
connect4_dropper.c 509 Bytes