@@ -828,8 +828,12 @@ static int userns_obj_priv_btf_success(int mnt_fd, struct token_lsm *lsm_skel)
828828 return validate_struct_ops_load (mnt_fd , true /* should succeed */ );
829829}
830830
831+ static const char * token_bpffs_custom_dir ()
832+ {
833+ return getenv ("BPF_SELFTESTS_BPF_TOKEN_DIR" ) ?: "/tmp/bpf-token-fs" ;
834+ }
835+
831836#define TOKEN_ENVVAR "LIBBPF_BPF_TOKEN_PATH"
832- #define TOKEN_BPFFS_CUSTOM "/bpf-token-fs"
833837
834838static int userns_obj_priv_implicit_token (int mnt_fd , struct token_lsm * lsm_skel )
835839{
@@ -892,6 +896,7 @@ static int userns_obj_priv_implicit_token(int mnt_fd, struct token_lsm *lsm_skel
892896
893897static int userns_obj_priv_implicit_token_envvar (int mnt_fd , struct token_lsm * lsm_skel )
894898{
899+ const char * custom_dir = token_bpffs_custom_dir ();
895900 LIBBPF_OPTS (bpf_object_open_opts , opts );
896901 struct dummy_st_ops_success * skel ;
897902 int err ;
@@ -909,10 +914,10 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
909914 * BPF token implicitly, unless pointed to it through
910915 * LIBBPF_BPF_TOKEN_PATH envvar
911916 */
912- rmdir (TOKEN_BPFFS_CUSTOM );
913- if (!ASSERT_OK (mkdir (TOKEN_BPFFS_CUSTOM , 0777 ), "mkdir_bpffs_custom" ))
917+ rmdir (custom_dir );
918+ if (!ASSERT_OK (mkdir (custom_dir , 0777 ), "mkdir_bpffs_custom" ))
914919 goto err_out ;
915- err = sys_move_mount (mnt_fd , "" , AT_FDCWD , TOKEN_BPFFS_CUSTOM , MOVE_MOUNT_F_EMPTY_PATH );
920+ err = sys_move_mount (mnt_fd , "" , AT_FDCWD , custom_dir , MOVE_MOUNT_F_EMPTY_PATH );
916921 if (!ASSERT_OK (err , "move_mount_bpffs" ))
917922 goto err_out ;
918923
@@ -925,7 +930,7 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
925930 goto err_out ;
926931 }
927932
928- err = setenv (TOKEN_ENVVAR , TOKEN_BPFFS_CUSTOM , 1 /*overwrite*/ );
933+ err = setenv (TOKEN_ENVVAR , custom_dir , 1 /*overwrite*/ );
929934 if (!ASSERT_OK (err , "setenv_token_path" ))
930935 goto err_out ;
931936
@@ -951,11 +956,11 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
951956 if (!ASSERT_ERR (err , "obj_empty_token_path_load" ))
952957 goto err_out ;
953958
954- rmdir (TOKEN_BPFFS_CUSTOM );
959+ rmdir (custom_dir );
955960 unsetenv (TOKEN_ENVVAR );
956961 return 0 ;
957962err_out :
958- rmdir (TOKEN_BPFFS_CUSTOM );
963+ rmdir (custom_dir );
959964 unsetenv (TOKEN_ENVVAR );
960965 return - EINVAL ;
961966}
0 commit comments