Skip to content

Commit 0fb2005

Browse files
Tao ChenKernel Patches Daemon
authored andcommitted
bpf/selftests: Add selftests for token info
A previous change added bpf_token_info to get token info with bpf_get_obj_info_by_fd, this patch adds a new test for token info. #461/12 token/bpf_token_info:OK Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Tao Chen <[email protected]>
1 parent 1913913 commit 0fb2005

File tree

1 file changed

+44
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+44
-0
lines changed

tools/testing/selftests/bpf/prog_tests/token.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,41 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
10471047

10481048
#define bit(n) (1ULL << (n))
10491049

1050+
static int userns_bpf_token_info(int mnt_fd, struct token_lsm *lsm_skel)
1051+
{
1052+
int err, token_fd = -1;
1053+
struct bpf_token_info info;
1054+
u32 len = sizeof(struct bpf_token_info);
1055+
1056+
/* create BPF token from BPF FS mount */
1057+
token_fd = bpf_token_create(mnt_fd, NULL);
1058+
if (!ASSERT_GT(token_fd, 0, "token_create")) {
1059+
err = -EINVAL;
1060+
goto cleanup;
1061+
}
1062+
1063+
memset(&info, 0, len);
1064+
err = bpf_obj_get_info_by_fd(token_fd, &info, &len);
1065+
if (!ASSERT_ERR(err, "bpf_obj_get_token_info"))
1066+
goto cleanup;
1067+
if (!ASSERT_EQ(info.allowed_cmds, bit(BPF_MAP_CREATE), "token_info_cmds_map_create")) {
1068+
err = -EINVAL;
1069+
goto cleanup;
1070+
}
1071+
if (!ASSERT_EQ(info.allowed_progs, bit(BPF_PROG_TYPE_XDP), "token_info_progs_xdp")) {
1072+
err = -EINVAL;
1073+
goto cleanup;
1074+
}
1075+
1076+
/* The BPF_PROG_TYPE_EXT is not set in token */
1077+
if (ASSERT_EQ(info.allowed_progs, bit(BPF_PROG_TYPE_EXT), "token_info_progs_ext"))
1078+
err = -EINVAL;
1079+
1080+
cleanup:
1081+
zclose(token_fd);
1082+
return err;
1083+
}
1084+
10501085
void test_token(void)
10511086
{
10521087
if (test__start_subtest("map_token")) {
@@ -1150,4 +1185,13 @@ void test_token(void)
11501185

11511186
subtest_userns(&opts, userns_obj_priv_implicit_token_envvar);
11521187
}
1188+
if (test__start_subtest("bpf_token_info")) {
1189+
struct bpffs_opts opts = {
1190+
.cmds = bit(BPF_MAP_CREATE),
1191+
.progs = bit(BPF_PROG_TYPE_XDP),
1192+
.attachs = ~0ULL,
1193+
};
1194+
1195+
subtest_userns(&opts, userns_bpf_token_info);
1196+
}
11531197
}

0 commit comments

Comments
 (0)