From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Tejun Heo <tj@kernel.org>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v4 02/16] selftests/bpf: Bind an exclusive map through a continuous fd_array
Date: Mon, 19 Oct 2026 05:23:42 +0200 [thread overview]
Message-ID: <20261019032401.2302823-3-memxor@gmail.com> (raw)
In-Reply-To: <20261019032401.2302823-1-memxor@gmail.com>
Load the exclusive program of map_excl with the map in a continuous
fd_array rather than through its insns alone, which has to work, and
the other program the same way, which has to be refused. The two
programs used to be identical and so shared a digest; give the second
one a value of its own so that the kernel can tell them apart.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../selftests/bpf/prog_tests/map_excl.c | 37 +++++++++++++++++++
tools/testing/selftests/bpf/progs/map_excl.c | 3 +-
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/map_excl.c b/tools/testing/selftests/bpf/prog_tests/map_excl.c
index 3f4422b9ffa6..9ff4cd3de2ec 100644
--- a/tools/testing/selftests/bpf/prog_tests/map_excl.c
+++ b/tools/testing/selftests/bpf/prog_tests/map_excl.c
@@ -161,12 +161,49 @@ static void test_map_excl_create_validation(void)
ASSERT_EQ(fd, -EINVAL, "reject size with NULL hash pointer");
}
+/*
+ * The exclusive map bound through a continuous fd_array rather than by an
+ * insn. The kernel resolves the array before it verifies the program, so it
+ * has to have the digest of the program at hand by then.
+ */
+static void test_map_excl_fd_array(void)
+{
+ struct map_excl *skel = map_excl__open();
+ LIBBPF_OPTS(bpf_prog_load_opts, opts);
+ int err, fd, map_fd;
+
+ if (!ASSERT_OK_PTR(skel, "map_excl__open"))
+ return;
+ err = bpf_map__set_exclusive_program(skel->maps.excl_map, skel->progs.should_have_access);
+ if (!ASSERT_OK(err, "bpf_map__set_exclusive_program"))
+ goto out;
+
+ bpf_program__set_autoload(skel->progs.should_have_access, true);
+ bpf_program__set_autoload(skel->progs.should_not_have_access, true);
+ err = bpf_object__prepare(skel->obj);
+ if (!ASSERT_OK(err, "map_excl prepare"))
+ goto out;
+
+ map_fd = bpf_map__fd(skel->maps.excl_map);
+ opts.fd_array = &map_fd;
+ opts.fd_array_cnt = 1;
+ fd = bpf_program__clone(skel->progs.should_have_access, &opts);
+ if (ASSERT_GE(fd, 0, "exclusive program with the map in fd_array"))
+ close(fd);
+ fd = bpf_program__clone(skel->progs.should_not_have_access, &opts);
+ ASSERT_EQ(fd, -EACCES, "other program with the map in fd_array");
+out:
+ map_excl__destroy(skel);
+}
+
void test_map_excl(void)
{
if (test__start_subtest("map_excl_allowed"))
test_map_excl_allowed();
if (test__start_subtest("map_excl_denied"))
test_map_excl_denied();
+ if (test__start_subtest("map_excl_fd_array"))
+ test_map_excl_fd_array();
if (test__start_subtest("map_excl_no_map_in_map"))
test_map_excl_no_map_in_map();
if (test__start_subtest("map_excl_no_map_iter"))
diff --git a/tools/testing/selftests/bpf/progs/map_excl.c b/tools/testing/selftests/bpf/progs/map_excl.c
index d461684728e4..90f127073dff 100644
--- a/tools/testing/selftests/bpf/progs/map_excl.c
+++ b/tools/testing/selftests/bpf/progs/map_excl.c
@@ -27,7 +27,8 @@ int should_have_access(void *ctx)
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
int should_not_have_access(void *ctx)
{
- int key = 0, value = 0xdeadbeef;
+ /* a different value, so that the two programs do not share a digest */
+ int key = 0, value = 0xbaadf00d;
bpf_map_update_elem(&excl_map, &key, &value, 0);
return 0;
--
2.53.0-Meta
next prev parent reply other threads:[~2026-10-19 3:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 3:23 [PATCH bpf-next v4 00/16] Fix some arena paper cuts Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 01/16] bpf: Check exclusive maps once the program digest is final Kumar Kartikeya Dwivedi
2026-10-19 3:46 ` sashiko-bot
2026-10-19 3:23 ` Kumar Kartikeya Dwivedi [this message]
2026-10-19 3:23 ` [PATCH bpf-next v4 03/16] libbpf: Keep the fd_array fill index out of bpf_program__clone() Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 04/16] selftests/bpf: Clone a program that calls a module kfunc Kumar Kartikeya Dwivedi
2026-10-19 3:31 ` sashiko-bot
2026-10-19 3:23 ` [PATCH bpf-next v4 05/16] bpf: Add the __arena and __nullable BTF type tags Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 06/16] bpf: Recognize __nullable on pointer members of kernel structs Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 07/16] bpf: Turn loads of __arena pointer members into arena pointers Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 08/16] selftests/bpf: Test __nullable pointer members Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 09/16] selftests/bpf: Test __arena " Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 10/16] selftests/bpf: Move the no-arena tests out of objects with an arena map Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 11/16] libbpf: Bind the arena of an object to every program in it Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 12/16] selftests/bpf: Test arena binding by libbpf Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 13/16] bpf: Set up the arena base only in functions that use it Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 14/16] libbpf: Render the arena type tag with its address space Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 15/16] selftests/bpf: Test the address space rendering of the arena type tag Kumar Kartikeya Dwivedi
2026-10-19 3:23 ` [PATCH bpf-next v4 16/16] selftests/bpf: Test an arena kfunc argument passed from a subprogram Kumar Kartikeya Dwivedi
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=20261019032401.2302823-3-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=tj@kernel.org \
/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.