BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token
@ 2026-11-25 15:31 Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

This series helps seamlessly run an application inside a user namespace
with a bpf_token delegation. The need for these changes was discussed at
my talk at this yeas's LPC:

https://lpc.events/event/20/contributions/2441/

The problem the series aims to fix is one we discovered while developing
the bpf-rbacd application discussed in the talk: when delegating
permissions with a bpf_token, a libbpf-based tracing application works
seamlessly when it is attaching an fentry program to a function that is
in vmlinux, but fails if it tries to attach the same program to a
function that's defined in a module. There are two reasons for this:

(1) When trying to find the BTF ID to attach to in the module, libbpf
    uses the BPF_BTF_GET_NEXT_ID command for the bpf() syscall, which
    requires global CAP_SYS_ADMIN.

(2) Even with the issue above fixed, libbpf does not have the token
    available at the time it does the BTF iteration.

The first patch relaxes the kernel's permission check to make it
possible to iterate BTF objects with bpf_token permissions, fixing
issue (1) above.

Patches 2-5 changes libbpf's behaviour around accessing tokens so that
token loading is done on object creation instead of on load, and passes
in the token when iterating BTF objects in the kernel, fixing issue (2)
above.

Patch 6 updates the selftests to correspond to the new behaviour, and
patch 7 adds a new test that checks that we can attach fentry programs
to module functions inside a user namespace, which was the original
issue resolved by this series.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
Toke Høiland-Jørgensen (7):
      bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token
      libbpf: Add bpf_*_get_next_id_opts() functions
      libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd
      libbpf: Move bpf_object_prepare_token() to object creation
      libbpf: Pass in token_fd when iterating kernel BTF objects
      selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test
      selftests/bpf: Add test for attaching fentry to a module with bpf_token

 include/uapi/linux/bpf.h                        |  5 ++-
 kernel/bpf/syscall.c                            | 33 ++++++++++++++----
 tools/include/uapi/linux/bpf.h                  |  5 ++-
 tools/lib/bpf/bpf.c                             | 45 +++++++++++++++++++++----
 tools/lib/bpf/bpf.h                             | 16 +++++++++
 tools/lib/bpf/libbpf.c                          | 16 +++++++--
 tools/lib/bpf/libbpf.map                        |  4 +++
 tools/testing/selftests/bpf/prog_tests/token.c  | 45 +++++++++++++++++++++++--
 tools/testing/selftests/bpf/progs/priv_module.c | 15 +++++++++
 9 files changed, 163 insertions(+), 21 deletions(-)
---
base-commit: 8dfce13340aeba06d1b68cc7648f37762244be65
change-id: 20261006-bpf-relax-get-next-id-6d025833eee7


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

The BPF_*_GET_NEXT_ID commands are currently restricted to system-wide
CAP_SYS_ADMIN, but iterating the objects themselves is not actually an
administrator-only operation, so this seems overly restrictive.

In particular, being able to walk the BTF IDs is necessary for libbpf to
attach to functions in modules. So the CAP_SYS_ADMIN restriction
prevents some BPF applications from working with permissions delegated
by a bpf_token.

Relax the permission check in bpf_obj_get_next_id() to
token_capable(CAP_BPF). There is no change to the operations that turn
the IDs into file descriptors (BPF_*_GET_FD_BY_ID commands).

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 include/uapi/linux/bpf.h       |  5 ++++-
 kernel/bpf/syscall.c           | 33 ++++++++++++++++++++++++++-------
 tools/include/uapi/linux/bpf.h |  5 ++++-
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 62de0919db72..cdc313f9ab14 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1786,7 +1786,10 @@ union bpf_attr {
 		};
 		__u32		next_id;
 		__u32		open_flags;
-		__s32		fd_by_id_token_fd;
+		union {
+			__s32		fd_by_id_token_fd;
+			__s32		get_next_id_token_fd;
+		};
 	};
 
 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index ec8e78792911..1440c10ea0cc 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -4872,21 +4872,40 @@ static int bpf_prog_test_run(const union bpf_attr *attr,
 	return ret;
 }
 
-#define BPF_OBJ_GET_NEXT_ID_LAST_FIELD next_id
+#define BPF_OBJ_GET_NEXT_ID_LAST_FIELD get_next_id_token_fd
 
-static int bpf_obj_get_next_id(const union bpf_attr *attr,
+static int bpf_obj_get_next_id(enum bpf_cmd cmd,
+			       const union bpf_attr *attr,
 			       union bpf_attr __user *uattr,
 			       struct idr *idr,
 			       spinlock_t *lock)
 {
+	struct bpf_token *token = NULL;
 	u32 next_id = attr->start_id;
 	int err = 0;
 
 	if (CHECK_ATTR(BPF_OBJ_GET_NEXT_ID) || next_id >= INT_MAX)
 		return -EINVAL;
 
-	if (!capable(CAP_SYS_ADMIN))
+	if (attr->open_flags & ~BPF_F_TOKEN_FD)
+		return -EINVAL;
+
+	if (attr->open_flags & BPF_F_TOKEN_FD) {
+		token = bpf_token_get_from_fd(attr->fd_by_id_token_fd);
+		if (IS_ERR(token))
+			return PTR_ERR(token);
+		if (!bpf_token_allow_cmd(token, cmd)) {
+			bpf_token_put(token);
+			token = NULL;
+		}
+	}
+
+	if (!bpf_token_capable(token, CAP_BPF)) {
+		bpf_token_put(token);
 		return -EPERM;
+	}
+
+	bpf_token_put(token);
 
 	next_id++;
 	spin_lock_bh(lock);
@@ -6523,15 +6542,15 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,
 		err = bpf_prog_test_run(&attr, uattr.user);
 		break;
 	case BPF_PROG_GET_NEXT_ID:
-		err = bpf_obj_get_next_id(&attr, uattr.user,
+		err = bpf_obj_get_next_id(cmd, &attr, uattr.user,
 					  &prog_idr, &prog_idr_lock);
 		break;
 	case BPF_MAP_GET_NEXT_ID:
-		err = bpf_obj_get_next_id(&attr, uattr.user,
+		err = bpf_obj_get_next_id(cmd, &attr, uattr.user,
 					  &map_idr, &map_idr_lock);
 		break;
 	case BPF_BTF_GET_NEXT_ID:
-		err = bpf_obj_get_next_id(&attr, uattr.user,
+		err = bpf_obj_get_next_id(cmd, &attr, uattr.user,
 					  &btf_idr, &btf_idr_lock);
 		break;
 	case BPF_PROG_GET_FD_BY_ID:
@@ -6586,7 +6605,7 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,
 		err = bpf_link_get_fd_by_id(&attr);
 		break;
 	case BPF_LINK_GET_NEXT_ID:
-		err = bpf_obj_get_next_id(&attr, uattr.user,
+		err = bpf_obj_get_next_id(cmd, &attr, uattr.user,
 					  &link_idr, &link_idr_lock);
 		break;
 	case BPF_ENABLE_STATS:
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 62de0919db72..cdc313f9ab14 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1786,7 +1786,10 @@ union bpf_attr {
 		};
 		__u32		next_id;
 		__u32		open_flags;
-		__s32		fd_by_id_token_fd;
+		union {
+			__s32		fd_by_id_token_fd;
+			__s32		get_next_id_token_fd;
+		};
 	};
 
 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:46   ` sashiko-bot
  2026-11-25 15:31 ` [PATCH bpf-next 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

Add opts-based variants of the bpf_*_get_next_id() functions which allow
passing in a token fd to add to the bpf() syscall.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/lib/bpf/bpf.c      | 43 +++++++++++++++++++++++++++++++++++++------
 tools/lib/bpf/bpf.h      | 16 ++++++++++++++++
 tools/lib/bpf/libbpf.map |  4 ++++
 3 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 38dcb31e8c0e..059c358c9744 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -1149,14 +1149,21 @@ int bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts *opts)
 	return libbpf_err_errno(ret);
 }
 
-static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd)
+static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd,
+			       const struct bpf_get_next_id_opts *opts)
 {
-	const size_t attr_sz = offsetofend(union bpf_attr, open_flags);
+	const size_t attr_sz = offsetofend(union bpf_attr, get_next_id_token_fd);
 	union bpf_attr attr;
 	int err;
 
+	if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts))
+		return libbpf_err(-EINVAL);
+
 	memset(&attr, 0, attr_sz);
 	attr.start_id = start_id;
+	attr.get_next_id_token_fd = OPTS_GET(opts, token_fd, 0);
+	if (attr.get_next_id_token_fd)
+		attr.open_flags = BPF_F_TOKEN_FD;
 
 	err = sys_bpf(cmd, &attr, attr_sz);
 	if (!err)
@@ -1167,22 +1174,46 @@ static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd)
 
 int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id)
 {
-	return bpf_obj_get_next_id(start_id, next_id, BPF_PROG_GET_NEXT_ID);
+	return bpf_obj_get_next_id(start_id, next_id, BPF_PROG_GET_NEXT_ID, NULL);
+}
+
+int bpf_prog_get_next_id_opts(__u32 start_id, __u32 *next_id,
+			      const struct bpf_get_next_id_opts *opts)
+{
+	return bpf_obj_get_next_id(start_id, next_id, BPF_PROG_GET_NEXT_ID, opts);
 }
 
 int bpf_map_get_next_id(__u32 start_id, __u32 *next_id)
 {
-	return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID);
+	return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID, NULL);
+}
+
+int bpf_map_get_next_id_opts(__u32 start_id, __u32 *next_id,
+			     const struct bpf_get_next_id_opts *opts)
+{
+	return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID, opts);
 }
 
 int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id)
 {
-	return bpf_obj_get_next_id(start_id, next_id, BPF_BTF_GET_NEXT_ID);
+	return bpf_obj_get_next_id(start_id, next_id, BPF_BTF_GET_NEXT_ID, NULL);
+}
+
+int bpf_btf_get_next_id_opts(__u32 start_id, __u32 *next_id,
+			      const struct bpf_get_next_id_opts *opts)
+{
+	return bpf_obj_get_next_id(start_id, next_id, BPF_BTF_GET_NEXT_ID, opts);
 }
 
 int bpf_link_get_next_id(__u32 start_id, __u32 *next_id)
 {
-	return bpf_obj_get_next_id(start_id, next_id, BPF_LINK_GET_NEXT_ID);
+	return bpf_obj_get_next_id(start_id, next_id, BPF_LINK_GET_NEXT_ID, NULL);
+}
+
+int bpf_link_get_next_id_opts(__u32 start_id, __u32 *next_id,
+			      const struct bpf_get_next_id_opts *opts)
+{
+	return bpf_obj_get_next_id(start_id, next_id, BPF_LINK_GET_NEXT_ID, opts);
 }
 
 int bpf_prog_get_fd_by_id_opts(__u32 id,
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index fe3b7fd8512b..cb5104734710 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -524,6 +524,22 @@ LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
 LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
 LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id);
 
+struct bpf_get_next_id_opts {
+	size_t sz; /* size of this struct for forward/backward compatibility */
+	__u32 token_fd;
+	size_t :0;
+};
+#define bpf_get_next_id_opts__last_field token_fd
+
+LIBBPF_API int bpf_prog_get_next_id_opts(__u32 start_id, __u32 *next_id,
+					 const struct bpf_get_next_id_opts *opts);
+LIBBPF_API int bpf_map_get_next_id_opts(__u32 start_id, __u32 *next_id,
+					 const struct bpf_get_next_id_opts *opts);
+LIBBPF_API int bpf_btf_get_next_id_opts(__u32 start_id, __u32 *next_id,
+					 const struct bpf_get_next_id_opts *opts);
+LIBBPF_API int bpf_link_get_next_id_opts(__u32 start_id, __u32 *next_id,
+					 const struct bpf_get_next_id_opts *opts);
+
 struct bpf_get_fd_by_id_opts {
 	size_t sz; /* size of this struct for forward/backward compatibility */
 	__u32 open_flags; /* permissions requested for the operation on fd */
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index a45666f546fa..899264fbb42d 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -458,7 +458,11 @@ LIBBPF_1.7.0 {
 
 LIBBPF_1.8.0 {
 	global:
+		bpf_btf_get_next_id_opts;
+		bpf_link_get_next_id_opts;
 		bpf_map__attach_cgroup_opts;
+		bpf_map_get_next_id_opts;
+		bpf_prog_get_next_id_opts;
 		bpf_prog_stream_open;
 		bpf_program__add_flags;
 		bpf_program__attach_tracing_multi;

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

The bpf_btf_get_fd_by_id_opts() function allows setting the token fd in
the opts, but leaves it to the caller to set the BPF_F_TOKEN_FD flag.
This is error-prone, and there's no reason we can't just set it on the
caller's behalf when an fd is supplied, so let's just do that.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/lib/bpf/bpf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 059c358c9744..3331524344a3 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -1276,6 +1276,8 @@ int bpf_btf_get_fd_by_id_opts(__u32 id,
 	attr.btf_id = id;
 	attr.open_flags = OPTS_GET(opts, open_flags, 0);
 	attr.fd_by_id_token_fd = OPTS_GET(opts, token_fd, 0);
+	if (attr.fd_by_id_token_fd)
+		attr.open_flags |= BPF_F_TOKEN_FD;
 
 	fd = sys_bpf_fd(BPF_BTF_GET_FD_BY_ID, &attr, attr_sz);
 	return libbpf_err_errno(fd);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 4/7] libbpf: Move bpf_object_prepare_token() to object creation
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
                   ` (2 preceding siblings ...)
  2026-11-25 15:31 ` [PATCH bpf-next 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

Move the automatic acquisition of a bpf_token from object prepare time
to object creation time. This ensures that the token is available for
any probing done before loading the object, in particular for BTF access
in bpf_program__set_attach_target().

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1efc0dd37b2e..2ede3081a20e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9278,6 +9278,7 @@ static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf,
 	err = err ? : bpf_object__init_maps(obj, opts);
 	err = err ? : bpf_object_init_progs(obj, opts);
 	err = err ? : bpf_object__collect_relos(obj);
+	err = err ? : bpf_object_prepare_token(obj);
 	if (err)
 		goto out;
 
@@ -9870,7 +9871,6 @@ static int bpf_object_prepare(struct bpf_object *obj, const char *target_btf_pat
 	}
 
 	err = bpf_object_check_gen_loader(obj);
-	err = err ? : bpf_object_prepare_token(obj);
 	err = err ? : bpf_object__probe_loading(obj);
 	err = err ? : bpf_object__load_vmlinux_btf(obj, false);
 	err = err ? : bpf_object__resolve_externs(obj, obj->kconfig);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
                   ` (3 preceding siblings ...)
  2026-11-25 15:31 ` [PATCH bpf-next 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:56   ` sashiko-bot
  2026-11-25 15:31 ` [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
  2026-11-25 15:31 ` [PATCH bpf-next 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen
  6 siblings, 1 reply; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

When loading module BTF, libbpf will iterate through the available BTF
IDs in the kernel and try to load them. This fails inside a user
namespace because of missing permissions. The kernel now supports
passing in a bpf_token to BPF_BTF_GET_NEXT_ID, so amend the iteration to
pass in a token if it exists.

Passing in the token doesn't work on older kernels, so if we get an
EINVAL back when trying to iterate, we reset any tokens and try again.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/lib/bpf/libbpf.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2ede3081a20e..65c2af92db2f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6014,6 +6014,10 @@ static bool is_btf_mod_allowed(const struct bpf_object *obj, const char *name)
 
 static int load_module_btfs(struct bpf_object *obj)
 {
+	DECLARE_LIBBPF_OPTS(bpf_get_next_id_opts, next_opts,
+			    .token_fd = obj->token_fd);
+	DECLARE_LIBBPF_OPTS(bpf_get_fd_by_id_opts, fd_opts,
+			    .token_fd = obj->token_fd);
 	struct bpf_btf_info info;
 	struct module_btf *mod_btf;
 	struct btf *btf;
@@ -6038,20 +6042,26 @@ static int load_module_btfs(struct bpf_object *obj)
 		return 0;
 
 	while (true) {
-		err = bpf_btf_get_next_id(id, &id);
+		err = bpf_btf_get_next_id_opts(id, &id, &next_opts);
 		if (err && errno == ENOENT)
 			return 0;
 		if (err && errno == EPERM) {
 			pr_debug("skipping module BTFs loading, missing privileges\n");
 			return 0;
 		}
+		if (err && errno == EINVAL && next_opts.token_fd) {
+			pr_debug("retrying module BTF load without token fd\n");
+			next_opts.token_fd = 0;
+			fd_opts.token_fd = 0;
+			err = bpf_btf_get_next_id_opts(id, &id, &next_opts);
+		}
 		if (err) {
 			err = -errno;
 			pr_warn("failed to iterate BTF objects: %s\n", errstr(err));
 			return err;
 		}
 
-		fd = bpf_btf_get_fd_by_id(id);
+		fd = bpf_btf_get_fd_by_id_opts(id, &fd_opts);
 		if (fd < 0) {
 			if (errno == ENOENT)
 				continue; /* expected race: BTF was unloaded */

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
                   ` (4 preceding siblings ...)
  2026-11-25 15:31 ` [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  2026-11-25 15:40   ` sashiko-bot
  2026-11-25 15:31 ` [PATCH bpf-next 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen
  6 siblings, 1 reply; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

Now that we changed the behaviour of libbpf to automatically load the
token fd on object creation, we can no longer rely on the absence of
bpf_object__prepare() preventing the token from being present. Instead,
explicitly disable the token by setting token_path to '\0' in the
token/obj_priv_freplace_prog_fail test.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/testing/selftests/bpf/prog_tests/token.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
index f2f5d36ae00a..dcb5e9f2d61e 100644
--- a/tools/testing/selftests/bpf/prog_tests/token.c
+++ b/tools/testing/selftests/bpf/prog_tests/token.c
@@ -797,7 +797,7 @@ static int userns_obj_priv_prog(int mnt_fd, struct token_lsm *lsm_skel)
 }
 
 static int userns_obj_priv_freplace_setup(int mnt_fd, struct priv_freplace_prog **fr_skel,
-					  struct priv_prog **skel, int *tgt_fd)
+					  struct priv_prog **skel, int *tgt_fd, bool fr_token)
 {
 	LIBBPF_OPTS(bpf_object_open_opts, opts);
 	int err;
@@ -813,6 +813,8 @@ static int userns_obj_priv_freplace_setup(int mnt_fd, struct priv_freplace_prog
 	if (!ASSERT_OK(err, "priv_prog__load"))
 		return -EINVAL;
 
+	if (!fr_token)
+		opts.bpf_token_path = '\0';
 	*fr_skel = priv_freplace_prog__open_opts(&opts);
 	if (!ASSERT_OK_PTR(*skel, "priv_freplace_prog__open_opts"))
 		return -EINVAL;
@@ -830,7 +832,7 @@ static int userns_obj_priv_freplace_prog(int mnt_fd, struct token_lsm *lsm_skel)
 	struct priv_prog *skel = NULL;
 	int err, tgt_fd;
 
-	err = userns_obj_priv_freplace_setup(mnt_fd, &fr_skel, &skel, &tgt_fd);
+	err = userns_obj_priv_freplace_setup(mnt_fd, &fr_skel, &skel, &tgt_fd, true);
 	if (!ASSERT_OK(err, "setup"))
 		goto out;
 
@@ -858,7 +860,7 @@ static int userns_obj_priv_freplace_prog_fail(int mnt_fd, struct token_lsm *lsm_
 	struct priv_prog *skel = NULL;
 	int err, tgt_fd;
 
-	err = userns_obj_priv_freplace_setup(mnt_fd, &fr_skel, &skel, &tgt_fd);
+	err = userns_obj_priv_freplace_setup(mnt_fd, &fr_skel, &skel, &tgt_fd, false);
 	if (!ASSERT_OK(err, "setup"))
 		goto out;
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH bpf-next 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token
  2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
                   ` (5 preceding siblings ...)
  2026-11-25 15:31 ` [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
@ 2026-11-25 15:31 ` Toke Høiland-Jørgensen
  6 siblings, 0 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-25 15:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend
  Cc: bpf, Toke Høiland-Jørgensen

Add a new subtest to the token prog_test which attaches an fentry
program to a module function. This requires libbpf to read the module
BTF information using a bpf_token, which is only possible with the
fixes in the previous commits.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 tools/testing/selftests/bpf/prog_tests/token.c  | 37 +++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/priv_module.c | 15 ++++++++++
 2 files changed, 52 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
index dcb5e9f2d61e..5861eaf2d589 100644
--- a/tools/testing/selftests/bpf/prog_tests/token.c
+++ b/tools/testing/selftests/bpf/prog_tests/token.c
@@ -26,6 +26,7 @@
 #include "token_kallsyms.skel.h"
 #include "token_lsm.skel.h"
 #include "priv_freplace_prog.skel.h"
+#include "priv_module.skel.h"
 
 static inline int sys_mount(const char *dev_name, const char *dir_name,
 			    const char *type, unsigned long flags,
@@ -1105,6 +1106,34 @@ static int userns_obj_priv_prog_kallsyms(int mnt_fd, struct token_lsm *lsm_skel)
 	return err;
 }
 
+static int userns_obj_priv_fentry_module(int mnt_fd, struct token_lsm *lsm_skel)
+{
+	LIBBPF_OPTS(bpf_object_open_opts, opts);
+	struct priv_module *skel = NULL;
+	char buf[256];
+	int err;
+
+	/* use bpf_token_path to provide BPF FS path */
+	snprintf(buf, sizeof(buf), "/proc/self/fd/%d", mnt_fd);
+	opts.bpf_token_path = buf;
+	skel = priv_module__open_opts(&opts);
+	if (!ASSERT_OK_PTR(skel, "priv_module__open_opts"))
+		return -EINVAL;
+
+	err = priv_module__load(skel);
+	if (!ASSERT_OK(err, "priv_module__load"))
+		goto out;
+
+	err = priv_module__attach(skel);
+	if (!ASSERT_OK(err, "priv_module__attach"))
+		goto out;
+
+out:
+	priv_module__destroy(skel);
+	return err;
+}
+
+
 #define bit(n) (1ULL << (n))
 
 static int userns_bpf_token_info(int mnt_fd, struct token_lsm *lsm_skel)
@@ -1201,6 +1230,14 @@ void serial_test_token(void)
 		};
 		subtest_userns(&opts, userns_obj_priv_freplace_prog_fail);
 	}
+	if (test__start_subtest("obj_priv_fentry_module")) {
+		struct bpffs_opts opts = {
+			.cmds = bit(BPF_BTF_LOAD) | bit(BPF_PROG_LOAD) | bit(BPF_BTF_GET_FD_BY_ID) | bit(BPF_BTF_GET_NEXT_ID),
+			.progs = bit(BPF_PROG_TYPE_TRACING),
+			.attachs = ~0ULL,
+		};
+		subtest_userns(&opts, userns_obj_priv_fentry_module);
+	}
 	if (test__start_subtest("obj_priv_btf_fail")) {
 		struct bpffs_opts opts = {
 			/* disallow BTF loading */
diff --git a/tools/testing/selftests/bpf/progs/priv_module.c b/tools/testing/selftests/bpf/progs/priv_module.c
new file mode 100644
index 000000000000..3743ceb43c42
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/priv_module.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+#include "../test_kmods/bpf_testmod.h"
+
+SEC("fentry/bpf_testmod_test_read")
+int BPF_PROG(handle_fentry)
+{
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test
  2026-11-25 15:31 ` [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
@ 2026-11-25 15:40   ` sashiko-bot
  0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 15:40 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/bpf: char literal assigned to pointer in
  userns_obj_priv_freplace_setup()
--

commit 2c21fda1bda78f7e8ad66a69f75df48fbe870eed
Author: Toke Høiland-Jørgensen <toke@toke.dk>

selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test

This commit updates userns_obj_priv_freplace_setup() to take a boolean
flag controlling whether the BPF token is disabled for the freplace
program in the obj_priv_freplace_prog_fail test.

> diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
> index f2f5d36ae00a4..dcb5e9f2d61e2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/token.c
> +++ b/tools/testing/selftests/bpf/prog_tests/token.c
> @@ -797,7 +797,7 @@ static int userns_obj_priv_prog(int mnt_fd, struct token_lsm *lsm_skel)
>  }
>  
>  static int userns_obj_priv_freplace_setup(int mnt_fd, struct priv_freplace_prog **fr_skel,
> -					  struct priv_prog **skel, int *tgt_fd)
> +					  struct priv_prog **skel, int *tgt_fd, bool fr_token)
>  {
>  	LIBBPF_OPTS(bpf_object_open_opts, opts);
>  	int err;
> @@ -813,6 +813,8 @@ static int userns_obj_priv_freplace_setup(int mnt_fd, struct priv_freplace_prog
>  	if (!ASSERT_OK(err, "priv_prog__load"))
>  		return -EINVAL;
>  
> +	if (!fr_token)
> +		opts.bpf_token_path = '\0';

[Severity: Medium]
Should opts.bpf_token_path be set to "" instead of '\0'?

opts.bpf_token_path is a const char *, so assigning the character constant
'\0' sets the pointer to NULL rather than an empty string.  Building with
Clang fails under -Werror,-Wnon-literal-null-conversion, and at runtime
bpf_object_prepare_token() checks for a non-NULL empty string
(obj->token_path && obj->token_path[0] == '\0') to skip token creation,
treating NULL as unspecified and falling back to the default bpffs path.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-bpf-relax-get-next-id-v1-0-49175227c8cf@toke.dk?part=6

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions
  2026-11-25 15:31 ` [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
@ 2026-11-25 15:46   ` sashiko-bot
  2026-11-26  9:48     ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 15:46 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] libbpf: wrong opts struct type in OPTS_VALID() in
  bpf_obj_get_next_id()
- [Medium] libbpf: new bpf_*_get_next_id_opts() symbols placed in
  LIBBPF_1.8.0
--

commit b7df30f0fa741fff328c3a531ed16f0239f39016
Author: Toke Høiland-Jørgensen <toke@toke.dk>

libbpf: Add bpf_*_get_next_id_opts() functions

This commit adds opts-based variants of the bpf_*_get_next_id() functions
that accept a struct bpf_get_next_id_opts with a token_fd field.

> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 38dcb31e8c0ed..059c358c97444 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -1149,14 +1149,21 @@ int bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts *opts)
>  	return libbpf_err_errno(ret);
>  }
>  
> -static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd)
> +static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd,
> +			       const struct bpf_get_next_id_opts *opts)
>  {
> -	const size_t attr_sz = offsetofend(union bpf_attr, open_flags);
> +	const size_t attr_sz = offsetofend(union bpf_attr, get_next_id_token_fd);
>  	union bpf_attr attr;
>  	int err;
>  
> +	if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts))
> +		return libbpf_err(-EINVAL);

[Severity: Medium]
Should OPTS_VALID() check bpf_get_next_id_opts instead of
bpf_get_fd_by_id_opts?  struct bpf_get_fd_by_id_opts has an extra __u32
open_flags field before token_fd, so validating against it skips checking
that the 4 bytes following token_fd in struct bpf_get_next_id_opts are
zeroed.

[ ... ]

> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index a45666f546fae..899264fbb42d0 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -458,7 +458,11 @@ LIBBPF_1.7.0 {
>  
>  LIBBPF_1.8.0 {
>  	global:
> +		bpf_btf_get_next_id_opts;
> +		bpf_link_get_next_id_opts;
>  		bpf_map__attach_cgroup_opts;
> +		bpf_map_get_next_id_opts;
> +		bpf_prog_get_next_id_opts;
>  		bpf_prog_stream_open;
>  		bpf_program__add_flags;
>  		bpf_program__attach_tracing_multi;

[Severity: Medium]
Should these new symbols be added to the LIBBPF_1.9.0 section rather than
the already-released LIBBPF_1.8.0 section?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-bpf-relax-get-next-id-v1-0-49175227c8cf@toke.dk?part=2

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects
  2026-11-25 15:31 ` [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
@ 2026-11-25 15:56   ` sashiko-bot
  0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 15:56 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] libbpf: EINVAL retry in load_module_btfs() skips EPERM and
  ENOENT checks
- [Medium] libbpf: unhandled EPERM in load_module_btfs() after token
  retry and fd fetch
--

commit 5f5f5856a82ba2af642d2a227760228210dc3824
Author: Toke Høiland-Jørgensen <toke@toke.dk>

libbpf: Pass in token_fd when iterating kernel BTF objects

This commit passes obj->token_fd to bpf_btf_get_next_id_opts() and
bpf_btf_get_fd_by_id_opts() in load_module_btfs(), retrying without a
token if the kernel returns EINVAL.

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 2ede3081a20eb..65c2af92db2f3 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -6014,6 +6014,10 @@ static bool is_btf_mod_allowed(const struct bpf_object *obj, const char *name)
>  
>  static int load_module_btfs(struct bpf_object *obj)
>  {
> +	DECLARE_LIBBPF_OPTS(bpf_get_next_id_opts, next_opts,
> +			    .token_fd = obj->token_fd);
> +	DECLARE_LIBBPF_OPTS(bpf_get_fd_by_id_opts, fd_opts,
> +			    .token_fd = obj->token_fd);
>  	struct bpf_btf_info info;
>  	struct module_btf *mod_btf;
>  	struct btf *btf;
> @@ -6038,20 +6042,26 @@ static int load_module_btfs(struct bpf_object *obj)
>  		return 0;
>  
>  	while (true) {
> -		err = bpf_btf_get_next_id(id, &id);
> +		err = bpf_btf_get_next_id_opts(id, &id, &next_opts);
>  		if (err && errno == ENOENT)
>  			return 0;
>  		if (err && errno == EPERM) {
>  			pr_debug("skipping module BTFs loading, missing privileges\n");
>  			return 0;
>  		}
> +		if (err && errno == EINVAL && next_opts.token_fd) {
> +			pr_debug("retrying module BTF load without token fd\n");
> +			next_opts.token_fd = 0;
> +			fd_opts.token_fd = 0;
> +			err = bpf_btf_get_next_id_opts(id, &id, &next_opts);
> +		}
>  		if (err) {
>  			err = -errno;
>  			pr_warn("failed to iterate BTF objects: %s\n", errstr(err));
>  			return err;
>  		}

[Severity: Medium]
Should the EINVAL retry in load_module_btfs() run before the ENOENT and
EPERM checks?

On an older kernel that rejects next_opts.token_fd with EINVAL, the
retried bpf_btf_get_next_id_opts() call without a token can return EPERM
(for example, inside an unprivileged user namespace) or ENOENT.  Because
those checks precede the retry block, load_module_btfs() falls through to
if (err) and fails with -EPERM or -ENOENT instead of skipping module BTF
loading and returning 0.

>  
> -		fd = bpf_btf_get_fd_by_id(id);
> +		fd = bpf_btf_get_fd_by_id_opts(id, &fd_opts);
>  		if (fd < 0) {
>  			if (errno == ENOENT)
>  				continue; /* expected race: BTF was unloaded */

[Severity: Medium]
What happens if bpf_btf_get_fd_by_id_opts() fails with EPERM after
bpf_btf_get_next_id_opts() succeeds?

In kernel/bpf/syscall.c, bpf_obj_get_next_id() only requires
bpf_token_allow_cmd(token, BPF_BTF_GET_NEXT_ID) and CAP_BPF, whereas
bpf_btf_get_fd_by_id() requires bpf_token_allow_cmd(token,
BPF_BTF_GET_FD_BY_ID) and CAP_SYS_ADMIN.  If the caller or token has
CAP_BPF without CAP_SYS_ADMIN (or allows BPF_BTF_GET_NEXT_ID without
BPF_BTF_GET_FD_BY_ID), bpf_btf_get_next_id_opts() succeeds and
bpf_btf_get_fd_by_id_opts() fails with EPERM, where the error path below
only ignores ENOENT and aborts load_module_btfs() with -EPERM instead of
skipping module BTF loading and returning 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-bpf-relax-get-next-id-v1-0-49175227c8cf@toke.dk?part=5

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions
  2026-11-25 15:46   ` sashiko-bot
@ 2026-11-26  9:48     ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 12+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26  9:48 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: bpf

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] libbpf: wrong opts struct type in OPTS_VALID() in
>   bpf_obj_get_next_id()
> - [Medium] libbpf: new bpf_*_get_next_id_opts() symbols placed in
>   LIBBPF_1.8.0

Will fix these and the other issues pointed out by the bot and respin.

pw-bot: cr

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-26  9:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 15:31 [PATCH bpf-next 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-25 15:31 ` [PATCH bpf-next 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
2026-11-25 15:31 ` [PATCH bpf-next 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
2026-11-25 15:46   ` sashiko-bot
2026-11-26  9:48     ` Toke Høiland-Jørgensen
2026-11-25 15:31 ` [PATCH bpf-next 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
2026-11-25 15:31 ` [PATCH bpf-next 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
2026-11-25 15:31 ` [PATCH bpf-next 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
2026-11-25 15:56   ` sashiko-bot
2026-11-25 15:31 ` [PATCH bpf-next 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
2026-11-25 15:40   ` sashiko-bot
2026-11-25 15:31 ` [PATCH bpf-next 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox