Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retire progs/test_sock_addr.c #7019

Closed

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: fcd1ed8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
version: 1

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot changed the title selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c Retire progs/test_sock_addr.c May 10, 2024
@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=852380 expired. Closing PR.

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: fcd1ed8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 80c5a07
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
version: 1

jrife added 8 commits May 12, 2024 17:08
…dr.c

This set of tests check that the BPF verifier rejects programs with
invalid return codes (recvmsg4 and recvmsg6 hooks can only return 1).
This patch replaces the tests in test_sock_addr.c with
verifier_sock_addr.c, a new verifier prog_tests for sockaddr hooks, in a
step towards fully retiring test_sock_addr.c.

Signed-off-by: Jordan Rife <jrife@google.com>
In preparation to migrate tests from bpf/test_sock_addr.c to
sock_addr.c, update BPF_SKEL_FUNCS so that it generates functions
based on prog_name instead of skel_name. This allows us to differentiate
between programs in the same skeleton.

Signed-off-by: Jordan Rife <jrife@google.com>
In preparation to move test cases from bpf/test_sock_addr.c that expect
LOAD_REJECT, this patch adds expected_attach_type and extends load_fn to
accept an expected attach type and a flag indicating whether or not
rejection is expected.

Signed-off-by: Jordan Rife <jrife@google.com>
In preparation to move test cases from bpf/test_sock_addr.c that expect
ATTACH_REJECT, this patch adds BPF_SKEL_FUNCS_RAW to generate load and
destroy functions that use bpf_prog_attach() to control the attach_type.

The normal load functions use bpf_program__attach_cgroup which does not
have the same degree of control over the attach type, as
bpf_program_attach_fd() calls bpf_link_create() with the attach type
extracted from prog using bpf_program__expected_attach_type(). It is
currently not possible to modify the attach type before
bpf_program__attach_cgroup() is called, since
bpf_program__set_expected_attach_type() has no effect after the program
is loaded.

Signed-off-by: Jordan Rife <jrife@google.com>
In preparation to move test cases from bpf/test_sock_addr.c that expect
system calls to return ENOTSUPP or EPERM, this patch propagates errno
from relevant system calls up to test_sock_addr() where the result can
be checked.

Signed-off-by: Jordan Rife <jrife@google.com>
Move wildcard IP sendmsg test case out of bpf/test_sock_addr.c into
prog_tests/sock_addr.c.

Signed-off-by: Jordan Rife <jrife@google.com>
This set of tests checks that sendmsg calls are rejected (return -EPERM)
when the sendmsg* hook returns 0. Replace those in bpf/test_sock_addr.c
with corresponding tests in prog_tests/sock_addr.c.

Signed-off-by: Jordan Rife <jrife@google.com>
Migrate test case from bpf/test_sock_addr.c ensuring that sendmsg
returns -ENOTSUPP when sending to an IPv4-mapped IPv6 address to
prog_tests/sock_addr.c.

Signed-off-by: Jordan Rife <jrife@google.com>
jrife added 9 commits May 12, 2024 17:08
Migrate test case from bpf/test_sock_addr.c ensuring that sendmsg
respects when sendmsg6 hooks rewrite the destination IP with the IPv6
wildcard IP, [::].

Signed-off-by: Jordan Rife <jrife@google.com>
Migrates tests from progs/test_sock_addr.c ensuring that programs fail
to load when the expected attach type does not match.

Signed-off-by: Jordan Rife <jrife@google.com>
Migrate test case from bpf/test_sock_addr.c ensuring that program
attachment fails when using an inappropriate attach type.

Signed-off-by: Jordan Rife <jrife@google.com>
Remove these test cases completely, as the same behavior is already
covered by other sendmsg* test cases in prog_tests/sock_addr.c. This
just rewrites the destination address similar to sendmsg_v4_prog and
sendmsg_v6_prog.

Signed-off-by: Jordan Rife <jrife@google.com>
Fully remove test_sock_addr.c and test_sock_addr.sh, as test coverage
has been fully moved to prog_tests/sock_addr.c.

Signed-off-by: Jordan Rife <jrife@google.com>
This patch expands verifier coverage for program return values to cover
bind, connect, sendmsg, getsockname, and getpeername hooks. It also
rounds out the recvmsg coverage by adding test cases for recvmsg_unix
hooks.

Signed-off-by: Jordan Rife <jrife@google.com>
This patch expands test coverage for EPERM tests to include connect and
bind calls and rounds out the coverage for sendmsg by adding tests for
sendmsg_unix.

Signed-off-by: Jordan Rife <jrife@google.com>
This expands coverage for getsockname and getpeername hooks to include
getsockname4, getsockname6, getpeername4, and getpeername6.

Signed-off-by: Jordan Rife <jrife@google.com>
This expands coverage for ATTACH_REJECT tests to include connect_unix,
sendmsg_unix, recvmsg*, getsockname*, and getpeername*.

Signed-off-by: Jordan Rife <jrife@google.com>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 20a759d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: bbe91a9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=852380
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c
Using index info to reconstruct a base tree...
M	tools/testing/selftests/bpf/prog_tests/verifier.c
A	tools/testing/selftests/bpf/test_sock_addr.c
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): tools/testing/selftests/bpf/test_sock_addr.c deleted in HEAD and modified in selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c. Version selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c of tools/testing/selftests/bpf/test_sock_addr.c left in tree.
CONFLICT (add/add): Merge conflict in tools/testing/selftests/bpf/progs/verifier_sock_addr.c
Auto-merging tools/testing/selftests/bpf/progs/verifier_sock_addr.c
Patch failed at 0001 selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc tools/testing/selftests/bpf/progs/verifier_sock_addr.c
index 9c31448a0f52,5081fa723d3a..000000000000
--- a/tools/testing/selftests/bpf/progs/verifier_sock_addr.c
+++ b/tools/testing/selftests/bpf/progs/verifier_sock_addr.c
@@@ -34,298 -34,4 +34,301 @@@ int recvmsg6_bad_return_code(struct bpf
  	return 0;
  }
  
++<<<<<<< HEAD
 +SEC("cgroup/recvmsg_unix")
 +__success
 +int recvmsg_unix_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/recvmsg_unix")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int recvmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/sendmsg4")
 +__success
 +int sendmsg4_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/sendmsg4")
 +__success
 +int sendmsg4_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/sendmsg4")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int sendmsg4_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/sendmsg6")
 +__success
 +int sendmsg6_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/sendmsg6")
 +__success
 +int sendmsg6_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/sendmsg6")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int sendmsg6_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/sendmsg_unix")
 +__success
 +int sendmsg_unix_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/sendmsg_unix")
 +__success
 +int sendmsg_unix_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/sendmsg_unix")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int sendmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/getpeername4")
 +__success
 +int getpeername4_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getpeername4")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getpeername4_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/getpeername6")
 +__success
 +int getpeername6_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getpeername6")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getpeername6_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/getpeername_unix")
 +__success
 +int getpeername_unix_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getpeername_unix")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getpeername_unix_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/getsockname4")
 +__success
 +int getsockname4_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getsockname4")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getsockname4_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/getsockname6")
 +__success
 +int getsockname6_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getsockname6")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getsockname6_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/getsockname_unix")
 +__success
 +int getsockname_unix_good_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/getsockname_unix")
 +__failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
 +int getsockname_unix_unix_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/bind4")
 +__success
 +int bind4_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/bind4")
 +__success
 +int bind4_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/bind4")
 +__success
 +int bind4_good_return_code_2(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/bind4")
 +__success
 +int bind4_good_return_code_3(struct bpf_sock_addr *ctx)
 +{
 +	return 3;
 +}
 +
 +SEC("cgroup/bind4")
 +__failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
 +int bind4_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 4;
 +}
 +
 +SEC("cgroup/bind6")
 +__success
 +int bind6_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/bind6")
 +__success
 +int bind6_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/bind6")
 +__success
 +int bind6_good_return_code_2(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/bind6")
 +__success
 +int bind6_good_return_code_3(struct bpf_sock_addr *ctx)
 +{
 +	return 3;
 +}
 +
 +SEC("cgroup/bind6")
 +__failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
 +int bind6_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 4;
 +}
 +
 +SEC("cgroup/connect4")
 +__success
 +int connect4_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/connect4")
 +__success
 +int connect4_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/connect4")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int connect4_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/connect6")
 +__success
 +int connect6_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/connect6")
 +__success
 +int connect6_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/connect6")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int connect6_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
 +SEC("cgroup/connect_unix")
 +__success
 +int connect_unix_good_return_code_0(struct bpf_sock_addr *ctx)
 +{
 +	return 0;
 +}
 +
 +SEC("cgroup/connect_unix")
 +__success
 +int connect_unix_good_return_code_1(struct bpf_sock_addr *ctx)
 +{
 +	return 1;
 +}
 +
 +SEC("cgroup/connect_unix")
 +__failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
 +int connect_unix_bad_return_code(struct bpf_sock_addr *ctx)
 +{
 +	return 2;
 +}
 +
++=======
++>>>>>>> selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c
  char _license[] SEC("license") = "GPL";
* Unmerged path tools/testing/selftests/bpf/test_sock_addr.c

@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=852380 irrelevant now. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant