mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
bpf: Add struct bpf_token_info
The 'commit 35f96de041 ("bpf: Introduce BPF token object")' added
BPF token as a new kind of BPF kernel object. And BPF_OBJ_GET_INFO_BY_FD
already used to get BPF object info, so we can also get token info with
this cmd.
One usage scenario, when program runs failed with token, because of
the permission failure, we can report what BPF token is allowing with
this API for debugging.
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Link: https://lore.kernel.org/r/20250716134654.1162635-1-chen.dylane@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Alexei Starovoitov
parent
8080500cba
commit
19d18fdfc7
@@ -5239,6 +5239,21 @@ static int bpf_link_get_info_by_fd(struct file *file,
|
||||
}
|
||||
|
||||
|
||||
static int token_get_info_by_fd(struct file *file,
|
||||
struct bpf_token *token,
|
||||
const union bpf_attr *attr,
|
||||
union bpf_attr __user *uattr)
|
||||
{
|
||||
struct bpf_token_info __user *uinfo = u64_to_user_ptr(attr->info.info);
|
||||
u32 info_len = attr->info.info_len;
|
||||
int err;
|
||||
|
||||
err = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(*uinfo), info_len);
|
||||
if (err)
|
||||
return err;
|
||||
return bpf_token_get_info_by_fd(token, attr, uattr);
|
||||
}
|
||||
|
||||
#define BPF_OBJ_GET_INFO_BY_FD_LAST_FIELD info.info
|
||||
|
||||
static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
|
||||
@@ -5262,6 +5277,9 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
|
||||
else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll)
|
||||
return bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
|
||||
attr, uattr);
|
||||
else if (fd_file(f)->f_op == &bpf_token_fops)
|
||||
return token_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
|
||||
attr, uattr);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user