* [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 15:19 ` bot+bpf-ci
2026-11-26 14:51 ` [PATCH bpf-next v3 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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), without touching the operations that turn the
IDs into file descriptors (BPF_*_GET_FD_BY_ID commands). Update the
capability documentation accordingly.
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
include/uapi/linux/bpf.h | 5 ++++-
include/uapi/linux/capability.h | 5 +++--
kernel/bpf/syscall.c | 33 ++++++++++++++++++++++++++-------
tools/include/uapi/linux/bpf.h | 5 ++++-
4 files changed, 37 insertions(+), 11 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/include/uapi/linux/capability.h b/include/uapi/linux/capability.h
index 06f206faee04..7906371c9c41 100644
--- a/include/uapi/linux/capability.h
+++ b/include/uapi/linux/capability.h
@@ -396,6 +396,7 @@ struct vfs_ns_cap_data {
* - Loading BPF Type Format (BTF) data
* - Retrieve xlated and JITed code of BPF programs
* - Use bpf_spin_lock() helper
+ * - Iterating over loaded programs, maps, links and BTF object IDs.
*
* CAP_PERFMON relaxes the verifier checks further:
* - BPF progs can use of pointer-to-integer conversions
@@ -405,8 +406,8 @@ struct vfs_ns_cap_data {
*
* CAP_SYS_ADMIN is required to use bpf_probe_write_user.
*
- * CAP_SYS_ADMIN is required to iterate system wide loaded
- * programs, maps, links, BTFs and convert their IDs to file descriptors.
+ * CAP_SYS_ADMIN is required to convert the IDs of loaded
+ * programs, maps, links, BTFs to file descriptors.
*
* CAP_PERFMON and CAP_BPF are required to load tracing programs.
* CAP_NET_ADMIN and CAP_BPF are required to load networking programs.
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] 13+ messages in thread* Re: [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token
2026-11-26 14:51 ` [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
@ 2026-11-26 15:19 ` bot+bpf-ci
0 siblings, 0 replies; 13+ messages in thread
From: bot+bpf-ci @ 2026-11-26 15:19 UTC (permalink / raw)
To: toke, ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
yonghong.song, jolsa, emil, ihor.solodrai, john.fastabend
Cc: bpf, toke, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1252 bytes --]
> bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token
TL;DR: Nit only: bpf_obj_get_next_id() reads attr->fd_by_id_token_fd instead
of the new get_next_id_token_fd; works since they share storage, but the new
field has no reader.
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> --- 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,
[ ... ]
> -#define BPF_OBJ_GET_NEXT_ID_LAST_FIELD next_id
> +#define BPF_OBJ_GET_NEXT_ID_LAST_FIELD get_next_id_token_fd
[ ... ]
> + if (attr->open_flags & BPF_F_TOKEN_FD) {
> + token = bpf_token_get_from_fd(attr->fd_by_id_token_fd);
This isn't a bug, but since the patch adds get_next_id_token_fd for these
commands, should bpf_obj_get_next_id() read attr->get_next_id_token_fd
instead of attr->fd_by_id_token_fd?
The two names share storage so it works, but get_next_id_token_fd is only
used by the BPF_OBJ_GET_NEXT_ID_LAST_FIELD macro and has no reader.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45845510673
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH bpf-next v3 2/7] libbpf: Add bpf_*_get_next_id_opts() functions
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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..773efb585bca 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_next_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..4a87b3500741 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -476,6 +476,10 @@ LIBBPF_1.8.0 {
LIBBPF_1.9.0 {
global:
+ bpf_btf_get_next_id_opts;
+ bpf_link_get_next_id_opts;
+ bpf_map_get_next_id_opts;
+ bpf_prog_get_next_id_opts;
bpf_program__load;
bpf_program__load_strategy;
bpf_program__set_load_strategy;
--
2.56.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH bpf-next v3 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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 773efb585bca..3d2dbf6d5fcf 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] 13+ messages in thread* [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
` (2 preceding siblings ...)
2026-11-26 14:51 ` [PATCH bpf-next v3 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 15:11 ` sashiko-bot
2026-11-26 15:47 ` bot+bpf-ci
2026-11-26 14:51 ` [PATCH bpf-next v3 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
` (2 subsequent siblings)
6 siblings, 2 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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().
To avoid the move re-instating the token fd into a generated loader,
clear the token fd in bpf_object__gen_loader().
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
tools/lib/bpf/libbpf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 540daf7752b4..1f1569a35f92 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9281,6 +9281,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;
@@ -9873,7 +9874,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);
@@ -10543,6 +10543,11 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
gen->opts = opts;
gen->swapped_endian = !is_native_endianness(obj);
obj->gen_loader = gen;
+ if (obj->token_fd) {
+ close(obj->token_fd);
+ obj->token_fd = 0;
+ obj->feat_cache->token_fd = 0;
+ }
return 0;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
2026-11-26 14:51 ` [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
@ 2026-11-26 15:11 ` sashiko-bot
2026-11-26 19:44 ` Toke Høiland-Jørgensen
2026-11-26 15:47 ` bot+bpf-ci
1 sibling, 1 reply; 13+ messages in thread
From: sashiko-bot @ 2026-11-26 15:11 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:
- [Low] libbpf: dead gen_loader check and host token probe in
bpf_object_open()
--
commit bfc72a1132d0b5606c8e46c132afab5bec32d57f
Author: Toke Høiland-Jørgensen <toke@toke.dk>
libbpf: Move bpf_object_prepare_token() to object creation
This commit moves bpf_object_prepare_token() from bpf_object_prepare() to
bpf_object_open() and closes any acquired token fd in
bpf_object__gen_loader().
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 540daf7752b45..1f1569a35f92a 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -9281,6 +9281,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;
>
> @@ -9873,7 +9874,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);
> @@ -10543,6 +10543,11 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
> gen->opts = opts;
> gen->swapped_endian = !is_native_endianness(obj);
> obj->gen_loader = gen;
> + if (obj->token_fd) {
> + close(obj->token_fd);
> + obj->token_fd = 0;
> + obj->feat_cache->token_fd = 0;
> + }
> return 0;
> }
[Severity: Low]
Does moving bpf_object_prepare_token() into bpf_object_open() make the
obj->gen_loader check in bpf_object_prepare_token() unreachable and
reintroduce host bpffs probing during offline loader generation?
Commit d92defe04ad5 ("libbpf: Skip BPF token preparation when generating
loader") added an early return on obj->gen_loader to
bpf_object_prepare_token() so that offline loader generation (such as
bpftool gen skeleton -L) would not probe /sys/fs/bpf or honor
LIBBPF_BPF_TOKEN_PATH on the build host. Because bpf_object_open() now
calls bpf_object_prepare_token() before returning obj to the caller,
bpf_object__gen_loader() cannot have been called yet and obj->gen_loader is
always NULL there. If LIBBPF_BPF_TOKEN_PATH or opts.bpf_token_path is set
to a non-empty path that cannot be opened or does not allow token creation
on the host, bpf_object_open() fails before bpf_object__gen_loader() can be
reached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-bpf-relax-get-next-id-v3-0-338e1d3077e7@toke.dk?part=4
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
2026-11-26 15:11 ` sashiko-bot
@ 2026-11-26 19:44 ` Toke Høiland-Jørgensen
0 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 19:44 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] libbpf: dead gen_loader check and host token probe in
> bpf_object_open()
> --
>
> commit bfc72a1132d0b5606c8e46c132afab5bec32d57f
> Author: Toke Høiland-Jørgensen <toke@toke.dk>
>
> libbpf: Move bpf_object_prepare_token() to object creation
>
> This commit moves bpf_object_prepare_token() from bpf_object_prepare() to
> bpf_object_open() and closes any acquired token fd in
> bpf_object__gen_loader().
>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 540daf7752b45..1f1569a35f92a 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -9281,6 +9281,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;
>>
>> @@ -9873,7 +9874,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);
>> @@ -10543,6 +10543,11 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
>> gen->opts = opts;
>> gen->swapped_endian = !is_native_endianness(obj);
>> obj->gen_loader = gen;
>> + if (obj->token_fd) {
>> + close(obj->token_fd);
>> + obj->token_fd = 0;
>> + obj->feat_cache->token_fd = 0;
>> + }
>> return 0;
>> }
>
> [Severity: Low]
> Does moving bpf_object_prepare_token() into bpf_object_open() make the
> obj->gen_loader check in bpf_object_prepare_token() unreachable and
> reintroduce host bpffs probing during offline loader generation?
>
> Commit d92defe04ad5 ("libbpf: Skip BPF token preparation when generating
> loader") added an early return on obj->gen_loader to
> bpf_object_prepare_token() so that offline loader generation (such as
> bpftool gen skeleton -L) would not probe /sys/fs/bpf or honor
> LIBBPF_BPF_TOKEN_PATH on the build host. Because bpf_object_open() now
> calls bpf_object_prepare_token() before returning obj to the caller,
> bpf_object__gen_loader() cannot have been called yet and obj->gen_loader is
> always NULL there. If LIBBPF_BPF_TOKEN_PATH or opts.bpf_token_path is set
> to a non-empty path that cannot be opened or does not allow token creation
> on the host, bpf_object_open() fails before bpf_object__gen_loader() can be
> reached.
I can remove the dead check for obj->gen_loader, but I don't think the
other issue is worth fixing; if someone explicitly sets a token path
during skeleton build and that makes the build fail, they can just...
not do that?
-Toke
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
2026-11-26 14:51 ` [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
2026-11-26 15:11 ` sashiko-bot
@ 2026-11-26 15:47 ` bot+bpf-ci
2026-11-26 19:46 ` Toke Høiland-Jørgensen
1 sibling, 1 reply; 13+ messages in thread
From: bot+bpf-ci @ 2026-11-26 15:47 UTC (permalink / raw)
To: toke, ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
yonghong.song, jolsa, emil, ihor.solodrai, john.fastabend
Cc: bpf, toke, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2164 bytes --]
> libbpf: Move bpf_object_prepare_token() to object creation
TL;DR: Creating the token at open time likely breaks selftest
token/obj_priv_freplace_prog_fail at this commit; the fix is in a later patch.
Could it be folded in or moved earlier to keep the series bisectable?
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -9281,6 +9281,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;
>
With this change, the token is created at open time. Does the selftest
token/obj_priv_freplace_prog_fail still pass at this commit?
userns_obj_priv_freplace_prog_fail() opens priv_freplace_prog with
opts.bpf_token_path set, does not call bpf_object__prepare(), and expects
this call to fail inside the user namespace:
err = bpf_program__set_attach_target(fr_skel->progs.new_xdp_prog2,
tgt_fd, "xdp_prog1");
if (ASSERT_ERR(err, "attach fails"))
Now bpf_program__set_attach_target() ->
libbpf_find_prog_btf_id(attach_func_name, attach_prog_fd,
prog->obj->token_fd) -> btf_load_from_kernel(..., token_fd) issues
BPF_BTF_GET_FD_BY_ID with BPF_F_TOKEN_FD. The bpffs in that subtest
delegates bit(BPF_BTF_GET_FD_BY_ID), so the call succeeds, ASSERT_ERR
fails and the subtest returns -EINVAL.
A later patch in the series, fd2e3e09e169 ("selftests/bpf: Explicitly
disable token in token/obj_priv_freplace_prog_fail test"), sets
bpf_token_path to "" for that subtest, and its commit message says the
test broke because of this libbpf change.
Could that test update be folded into this commit or placed before it, so
that the series stays bisectable for test_progs?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45845510673
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
2026-11-26 15:47 ` bot+bpf-ci
@ 2026-11-26 19:46 ` Toke Høiland-Jørgensen
0 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 19:46 UTC (permalink / raw)
To: bot+bpf-ci, ast, daniel, andrii, eddyz87, memxor, martin.lau,
song, yonghong.song, jolsa, emil, ihor.solodrai, john.fastabend
Cc: bpf, ast, andrii, daniel, martin.lau, eddyz87, yonghong.song,
mason, ihor.solodrai
bot+bpf-ci@kernel.org writes:
>> libbpf: Move bpf_object_prepare_token() to object creation
>
> TL;DR: Creating the token at open time likely breaks selftest
> token/obj_priv_freplace_prog_fail at this commit; the fix is in a later patch.
> Could it be folded in or moved earlier to keep the series bisectable?
It's not possible to move the selftest update before this commit (then
the selftest would just be broken by the commit that updates it, and
fixed by this one, instead of the reverse).
I am under the impression that the "keep selftest updates in a separate
commit" rule takes precedence over the "keep selftests working for every
commit rule", in which case keeping it like this is the right thing to
do.
Am I wrong to think so?
-Toke
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH bpf-next v3 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
` (3 preceding siblings ...)
2026-11-26 14:51 ` [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen
6 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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 | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1f1569a35f92..2f4370623a42 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6017,6 +6017,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;
@@ -6041,7 +6045,13 @@ 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 == 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 && errno == ENOENT)
return 0;
if (err && errno == EPERM) {
@@ -6054,10 +6064,14 @@ static int load_module_btfs(struct bpf_object *obj)
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 */
+ if (errno == EPERM) {
+ pr_debug("skipping module BTFs loading, missing privileges\n");
+ return 0;
+ }
err = -errno;
pr_warn("failed to get BTF object #%u FD: %s\n", id, errstr(err));
return err;
--
2.56.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH bpf-next v3 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
` (4 preceding siblings ...)
2026-11-26 14:51 ` [PATCH bpf-next v3 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen
6 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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 and empty string
in the token/obj_priv_freplace_prog_fail test.
Drop the now redundant bpf_object__prepare() call in the succeeding
test, and update the test comment accordingly.
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
tools/testing/selftests/bpf/prog_tests/token.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
index f2f5d36ae00a..6499db1704bb 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 = "";
*fr_skel = priv_freplace_prog__open_opts(&opts);
if (!ASSERT_OK_PTR(*skel, "priv_freplace_prog__open_opts"))
return -EINVAL;
@@ -821,23 +823,17 @@ static int userns_obj_priv_freplace_setup(int mnt_fd, struct priv_freplace_prog
return 0;
}
-/* Verify that freplace works from user namespace, because bpf token is loaded
- * in bpf_object__prepare
- */
+/* Verify that freplace works from user namespace */
static int userns_obj_priv_freplace_prog(int mnt_fd, struct token_lsm *lsm_skel)
{
struct priv_freplace_prog *fr_skel = NULL;
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;
- err = bpf_object__prepare(fr_skel->obj);
- if (!ASSERT_OK(err, "freplace__prepare"))
- goto out;
-
err = bpf_program__set_attach_target(fr_skel->progs.new_xdp_prog2, tgt_fd, "xdp_prog1");
if (!ASSERT_OK(err, "set_attach_target"))
goto out;
@@ -858,7 +854,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] 13+ messages in thread* [PATCH bpf-next v3 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
` (5 preceding siblings ...)
2026-11-26 14:51 ` [PATCH bpf-next v3 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
@ 2026-11-26 14:51 ` Toke Høiland-Jørgensen
6 siblings, 0 replies; 13+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-26 14:51 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 6499db1704bb..b16b9b4d3d45 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,
@@ -1099,6 +1100,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)
@@ -1195,6 +1224,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] 13+ messages in thread