From: Jordan Rife <jrife@google.com>
To: bpf@vger.kernel.org
Cc: Jordan Rife <jrife@google.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
Shuah Khan <shuah@kernel.org>,
Geliang Tang <tanggeliang@kylinos.cn>,
Daan De Meyer <daan.j.demeyer@gmail.com>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>,
linux-kselftest@vger.kernel.org
Subject: [PATCH v1 bpf-next 10/17] selftests/bpf: Migrate expected_attach_type tests
Date: Fri, 10 May 2024 14:02:27 -0500 [thread overview]
Message-ID: <20240510190246.3247730-11-jrife@google.com> (raw)
In-Reply-To: <20240510190246.3247730-1-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>
---
.../selftests/bpf/prog_tests/sock_addr.c | 96 +++++++++++++++++++
tools/testing/selftests/bpf/test_sock_addr.c | 84 ----------------
2 files changed, 96 insertions(+), 84 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
index e3c450d11b9ef..8c7c56f997549 100644
--- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c
+++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
@@ -490,6 +490,22 @@ static struct sock_addr_test tests[] = {
NULL,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_BIND,
+ "bind4: load prog with wrong expected attach type",
+ bind_v4_prog_load,
+ bind_v4_prog_destroy,
+ BPF_CGROUP_INET6_BIND,
+ &user_ops,
+ AF_INET,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
{
SOCK_ADDR_TEST_BIND,
"bind6: bind (stream)",
@@ -522,6 +538,22 @@ static struct sock_addr_test tests[] = {
NULL,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_BIND,
+ "bind6: load prog with wrong expected attach type",
+ bind_v6_prog_load,
+ bind_v6_prog_destroy,
+ BPF_CGROUP_INET4_BIND,
+ &user_ops,
+ AF_INET6,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
/* bind - kernel calls */
{
@@ -622,6 +654,22 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_CONNECT,
+ "connect4: load prog with wrong expected attach type",
+ connect_v4_prog_load,
+ connect_v4_prog_destroy,
+ BPF_CGROUP_INET6_CONNECT,
+ &user_ops,
+ AF_INET,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
{
SOCK_ADDR_TEST_CONNECT,
"connect6: connect (stream)",
@@ -654,6 +702,22 @@ static struct sock_addr_test tests[] = {
SRC6_REWRITE_IP,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_CONNECT,
+ "connect6: load prog with wrong expected attach type",
+ connect_v6_prog_load,
+ connect_v6_prog_destroy,
+ BPF_CGROUP_INET4_CONNECT,
+ &user_ops,
+ AF_INET6,
+ SOCK_STREAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
{
SOCK_ADDR_TEST_CONNECT,
"connect_unix: connect (stream)",
@@ -786,6 +850,22 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SYSCALL_EPERM,
},
+ {
+ SOCK_ADDR_TEST_SENDMSG,
+ "sendmsg4: load prog with wrong expected attach type",
+ sendmsg_v4_prog_load,
+ sendmsg_v4_prog_destroy,
+ BPF_CGROUP_UDP6_SENDMSG,
+ &user_ops,
+ AF_INET,
+ SOCK_DGRAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg6: sendmsg (dgram)",
@@ -866,6 +946,22 @@ static struct sock_addr_test tests[] = {
SRC6_REWRITE_IP,
SUCCESS,
},
+ {
+ SOCK_ADDR_TEST_SENDMSG,
+ "sendmsg6: load prog with wrong expected attach type",
+ sendmsg_v6_prog_load,
+ sendmsg_v6_prog_destroy,
+ BPF_CGROUP_UDP4_SENDMSG,
+ &user_ops,
+ AF_INET6,
+ SOCK_DGRAM,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ LOAD_REJECT,
+ },
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg_unix: sendmsg (dgram)",
diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c
index 85fb2a793be50..4ecbc72477f1f 100644
--- a/tools/testing/selftests/bpf/test_sock_addr.c
+++ b/tools/testing/selftests/bpf/test_sock_addr.c
@@ -97,20 +97,6 @@ static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
static struct sock_addr_test tests[] = {
/* bind */
- {
- "bind4: load prog with wrong expected attach type",
- bind4_prog_load,
- BPF_CGROUP_INET6_BIND,
- BPF_CGROUP_INET4_BIND,
- AF_INET,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"bind4: attach prog with wrong attach type",
bind4_prog_load,
@@ -125,20 +111,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
- {
- "bind6: load prog with wrong expected attach type",
- bind6_prog_load,
- BPF_CGROUP_INET4_BIND,
- BPF_CGROUP_INET6_BIND,
- AF_INET6,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"bind6: attach prog with wrong attach type",
bind6_prog_load,
@@ -155,20 +127,6 @@ static struct sock_addr_test tests[] = {
},
/* connect */
- {
- "connect4: load prog with wrong expected attach type",
- connect4_prog_load,
- BPF_CGROUP_INET6_CONNECT,
- BPF_CGROUP_INET4_CONNECT,
- AF_INET,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"connect4: attach prog with wrong attach type",
connect4_prog_load,
@@ -183,20 +141,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
- {
- "connect6: load prog with wrong expected attach type",
- connect6_prog_load,
- BPF_CGROUP_INET4_CONNECT,
- BPF_CGROUP_INET6_CONNECT,
- AF_INET6,
- SOCK_STREAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"connect6: attach prog with wrong attach type",
connect6_prog_load,
@@ -213,20 +157,6 @@ static struct sock_addr_test tests[] = {
},
/* sendmsg */
- {
- "sendmsg4: load prog with wrong expected attach type",
- sendmsg4_rw_asm_prog_load,
- BPF_CGROUP_UDP6_SENDMSG,
- BPF_CGROUP_UDP4_SENDMSG,
- AF_INET,
- SOCK_DGRAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"sendmsg4: attach prog with wrong attach type",
sendmsg4_rw_asm_prog_load,
@@ -255,20 +185,6 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SUCCESS,
},
- {
- "sendmsg6: load prog with wrong expected attach type",
- sendmsg6_rw_asm_prog_load,
- BPF_CGROUP_UDP4_SENDMSG,
- BPF_CGROUP_UDP6_SENDMSG,
- AF_INET6,
- SOCK_DGRAM,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- LOAD_REJECT,
- },
{
"sendmsg6: attach prog with wrong attach type",
sendmsg6_rw_asm_prog_load,
--
2.45.0.118.g7fe29c98d7-goog
next prev parent reply other threads:[~2024-05-10 19:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 19:02 [PATCH v1 bpf-next 00/17] Retire progs/test_sock_addr.c Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 01/17] selftests/bpf: Migrate recvmsg* return code tests to verifier_sock_addr.c Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 02/17] selftests/bpf: Use program name for skel load/destroy functions Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 03/17] selftests/bpf: Handle LOAD_REJECT test cases Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 04/17] selftests/bpf: Handle ATTACH_REJECT " Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 05/17] selftests/bpf: Handle SYSCALL_EPERM and SYSCALL_ENOTSUPP " Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 06/17] selftests/bpf: Migrate WILDCARD_IP test Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 07/17] selftests/bpf: Migrate sendmsg deny test cases Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 08/17] selftests/bpf: Migrate sendmsg6 v4 mapped address tests Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 09/17] selftests/bpf: Migrate wildcard destination rewrite test Jordan Rife
2024-05-10 19:02 ` Jordan Rife [this message]
2024-05-10 19:02 ` [PATCH v1 bpf-next 11/17] selftests/bpf: Migrate ATTACH_REJECT test cases Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 12/17] selftests/bpf: Remove redundant sendmsg " Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 13/17] selftests/bpf: Retire test_sock_addr.(c|sh) Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 14/17] selftests/bpf: Expand sockaddr program return value tests Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 15/17] sefltests/bpf: Expand sockaddr hook deny tests Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 16/17] selftests/bpf: Expand getsockname and getpeername tests Jordan Rife
2024-05-10 19:02 ` [PATCH v1 bpf-next 17/17] selftests/bpf: Expand ATTACH_REJECT tests Jordan Rife
2024-05-10 22:05 ` [PATCH v1 bpf-next 00/17] Retire progs/test_sock_addr.c Andrii Nakryiko
2024-05-10 22:12 ` Jordan Rife
2024-05-10 22:32 ` Andrii Nakryiko
2024-05-13 0:20 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240510190246.3247730-11-jrife@google.com \
--to=jrife@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daan.j.demeyer@gmail.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=shung-hsi.yu@suse.com \
--cc=song@kernel.org \
--cc=tanggeliang@kylinos.cn \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox