@@ -1047,6 +1047,41 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
1047
1047
1048
1048
#define bit (n ) (1ULL << (n))
1049
1049
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
+
1050
1085
void test_token (void )
1051
1086
{
1052
1087
if (test__start_subtest ("map_token" )) {
@@ -1150,4 +1185,13 @@ void test_token(void)
1150
1185
1151
1186
subtest_userns (& opts , userns_obj_priv_implicit_token_envvar );
1152
1187
}
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
+ }
1153
1197
}
0 commit comments