Commit 1e0a8367 authored by Jordan Rife's avatar Jordan Rife Committed by Alexei Starovoitov

selftests/bpf: Expand sockaddr program return value tests

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: default avatarJordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20240510190246.3247730-15-jrife@google.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 61ecfdfc
......@@ -34,4 +34,298 @@ int recvmsg6_bad_return_code(struct bpf_sock_addr *ctx)
return 0;
}
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;
}
char _license[] SEC("license") = "GPL";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment