All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vernet <void@manifault.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com,
	tj@kernel.org
Subject: [PATCH bpf-next 2/2] selftests/bpf: Add test for resizing data map with struct_ops
Date: Wed, 24 Jul 2024 12:14:59 -0500	[thread overview]
Message-ID: <20240724171459.281234-2-void@manifault.com> (raw)
In-Reply-To: <20240724171459.281234-1-void@manifault.com>

Tests that if you resize a map after opening a skel, that it doesn't
cause a UAF which causes a struct_ops map to fail to be able to load.

Signed-off-by: David Vernet <void@manifault.com>
---
 .../bpf/prog_tests/struct_ops_resize.c        | 30 +++++++++++++++++++
 .../selftests/bpf/progs/struct_ops_resize.c   | 24 +++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
 create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_resize.c

diff --git a/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c b/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
new file mode 100644
index 000000000000..7584f91c2bd1
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "struct_ops_resize.skel.h"
+
+static void resize_datasec(void)
+{
+	struct struct_ops_resize *skel;
+	int err;
+
+	skel = struct_ops_resize__open();
+	if (!ASSERT_OK_PTR(skel, "struct_ops_resize__open"))
+		return;
+
+	err  = bpf_map__set_value_size(skel->maps.data_resizable, 1 << 15);
+	if (!ASSERT_OK(err, "bpf_map__set_value_size"))
+		goto cleanup;
+
+	err = struct_ops_resize__load(skel);
+	ASSERT_OK(err, "struct_ops_resize__load");
+
+cleanup:
+	struct_ops_resize__destroy(skel);
+}
+
+void test_struct_ops_resize(void)
+{
+	if (test__start_subtest("resize_datasec"))
+		resize_datasec();
+}
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_resize.c b/tools/testing/selftests/bpf/progs/struct_ops_resize.c
new file mode 100644
index 000000000000..d0b235f4bbaa
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/struct_ops_resize.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+char resizable[1] SEC(".data.resizable");
+
+SEC("struct_ops/test_1")
+int BPF_PROG(test_1)
+{
+	return 0;
+}
+
+struct bpf_testmod_ops {
+	int (*test_1)(void);
+};
+
+SEC(".struct_ops.link")
+struct bpf_testmod_ops testmod = {
+	.test_1 = (void *)test_1
+};
-- 
2.45.2


  reply	other threads:[~2024-07-24 17:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-24 17:14 [PATCH bpf-next 1/2] libbpf: Don't take direct pointers into BTF data from st_ops David Vernet
2024-07-24 17:14 ` David Vernet [this message]
2024-07-25  0:12   ` [PATCH bpf-next 2/2] selftests/bpf: Add test for resizing data map with struct_ops Andrii Nakryiko
2024-07-25  2:54     ` David Vernet
2024-07-25  0:20 ` [PATCH bpf-next 1/2] libbpf: Don't take direct pointers into BTF data from st_ops 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=20240724171459.281234-2-void@manifault.com \
    --to=void@manifault.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.