From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: "Toke Høiland-Jørgensen" <toke@redhat.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"David S. Miller" <davem@davemloft.net>,
"Jesper Dangaard Brouer" <brouer@redhat.com>,
"Andrea Arcangeli" <aarcange@redhat.com>,
"Clark Williams" <williams@redhat.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf 2/2] bpf/selftests: test that kernel rejects a TCP CC with an invalid license
Date: Thu, 25 Mar 2021 16:40:34 +0100 [thread overview]
Message-ID: <20210325154034.85346-2-toke@redhat.com> (raw)
In-Reply-To: <20210325154034.85346-1-toke@redhat.com>
This adds a selftest to check that the verifier rejects a TCP CC struct_ops
with a non-GPL license. To save having to add a whole new BPF object just
for this, reuse the dctcp CC, but rewrite the license field before loading.
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
.../selftests/bpf/prog_tests/bpf_tcp_ca.c | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index 37c5494a0381..613cf8a00b22 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -227,10 +227,41 @@ static void test_dctcp(void)
bpf_dctcp__destroy(dctcp_skel);
}
+static void test_invalid_license(void)
+{
+ /* We want to check that the verifier refuses to load a non-GPL TCP CC.
+ * Rather than create a whole new file+skeleton, just reuse an existing
+ * object and rewrite the license in memory after loading. Sine libbpf
+ * doesn't expose this, we define a struct that includes the first couple
+ * of internal fields for struct bpf_object so we can overwrite the right
+ * bits. Yes, this is a bit of a hack, but it makes the test a lot simpler.
+ */
+ struct bpf_object_fragment {
+ char name[BPF_OBJ_NAME_LEN];
+ char license[64];
+ } *obj;
+ struct bpf_dctcp *skel;
+ int err;
+
+ skel = bpf_dctcp__open();
+ if (CHECK(!skel, "bpf_dctcp__open", "failed\n"))
+ return;
+
+ obj = (void *)skel->obj;
+ obj->license[0] = 'X'; // turns 'GPL' into 'XPL' which will fail the check
+
+ err = bpf_dctcp__load(skel);
+ CHECK(err != -LIBBPF_ERRNO__VERIFY, "bpf_dctcp__load", "err:%d\n", err);
+
+ bpf_dctcp__destroy(skel);
+}
+
void test_bpf_tcp_ca(void)
{
if (test__start_subtest("dctcp"))
test_dctcp();
if (test__start_subtest("cubic"))
test_cubic();
+ if (test__start_subtest("invalid_license"))
+ test_invalid_license();
}
--
2.31.0
next prev parent reply other threads:[~2021-03-25 15:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 15:40 [PATCH bpf 1/2] bpf: enforce that struct_ops programs be GPL-only Toke Høiland-Jørgensen
2021-03-25 15:40 ` Toke Høiland-Jørgensen [this message]
2021-03-25 18:32 ` [PATCH bpf 2/2] bpf/selftests: test that kernel rejects a TCP CC with an invalid license Martin KaFai Lau
2021-03-25 20:38 ` Toke Høiland-Jørgensen
2021-03-25 18:15 ` [PATCH bpf 1/2] bpf: enforce that struct_ops programs be GPL-only Martin KaFai Lau
2021-03-25 20:37 ` Toke Høiland-Jørgensen
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=20210325154034.85346-2-toke@redhat.com \
--to=toke@redhat.com \
--cc=aarcange@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=williams@redhat.com \
--cc=yhs@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).