lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210325154034.85346-2-toke@redhat.com>
Date:   Thu, 25 Mar 2021 16:40:34 +0100
From:   Toke Høiland-Jørgensen <toke@...hat.com>
To:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>
Cc:     Toke Høiland-Jørgensen <toke@...hat.com>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        Stanislav Fomichev <sdf@...gle.com>,
        "David S. Miller" <davem@...emloft.net>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        Andrea Arcangeli <aarcange@...hat.com>,
        Clark Williams <williams@...hat.com>, bpf@...r.kernel.org,
        netdev@...r.kernel.org
Subject: [PATCH bpf 2/2] bpf/selftests: test that kernel rejects a TCP CC with an invalid license

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@...hat.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ