diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index eaf1e23429f7739e4fd74ec6c2050ad619683bf5..b8f137330ef5d15ff812f20857e1e583b46abe57 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -68,7 +68,7 @@ #define ISOLATE_PATH_SIZE 4096 #define HM_DEC_IOCTL_BASE 's' #define HM_ADD_ISOLATE_DIR 16 -#define ADD_ISOLATE_DIR_CMD _IOWR(HM_DEC_IOCTL_BASE, HM_ADD_ISOLATE_DIR, CustomSandboxIsolateDirInfo) +#define ADD_ISOLATE_DIR_CMD _IOWR(HM_DEC_IOCTL_BASE, HM_ADD_ISOLATE_DIR, IsolateDirInfo) static int SetProcessName(const AppSpawnMgr *content, const AppSpawningCtx *property) { @@ -384,9 +384,9 @@ static int SpawnSetPreInstalledFlag(AppSpawningCtx *property) typedef struct { char isolatePath[ISOLATE_PATH_NUM][ISOLATE_PATH_SIZE]; int pathNum; -} CustomSandboxIsolateDirInfo; +} IsolateDirInfo; -APPSPAWN_STATIC int SetIsolateDirForCustomSandbox(const AppSpawningCtx *property) +APPSPAWN_STATIC int SetIsolateDir(const AppSpawningCtx *property) { #ifdef CUSTOM_SANDBOX const char *bundleName = GetBundleName(property); @@ -395,11 +395,12 @@ APPSPAWN_STATIC int SetIsolateDirForCustomSandbox(const AppSpawningCtx *property AppSpawnMsgDacInfo *dacInfo = (AppSpawnMsgDacInfo *)GetAppProperty(property, TLV_DAC_INFO); APPSPAWN_CHECK(dacInfo != NULL, return APPSPAWN_TLV_NONE, "No tlv %{public}d in msg %{public}s", TLV_DOMAIN_INFO, bundleName); + APPSPAWN_ONLY_EXPER(dacInfo->uid == 0, return 0); int ret = 0; - CustomSandboxIsolateDirInfo isolateDirInfo = {0}; - ret = snprintf_s(isolateDirInfo.isolatePath[0], ISOLATE_PATH_SIZE, ISOLATE_PATH_SIZE - 1, "%s/%u/%s/%s", - "/data/app/el2", dacInfo->uid / UID_BASE, "base", bundleName); + IsolateDirInfo isolateDirInfo = {0}; + ret = snprintf_s(isolateDirInfo.isolatePath[0], ISOLATE_PATH_SIZE, ISOLATE_PATH_SIZE - 1, "%s/%u/%s", + "/data/app/el2", dacInfo->uid / UID_BASE, "base"); APPSPAWN_CHECK(ret >= 0, return ret, "snprintf_s el2 path failed, errno %{public}d", errno); ret = snprintf_s(isolateDirInfo.isolatePath[1], ISOLATE_PATH_SIZE, ISOLATE_PATH_SIZE - 1, "%s/%u/%s", "/storage/media", dacInfo->uid / UID_BASE, "local/files/Docs"); @@ -432,11 +433,9 @@ static int SpawnInitSpawningEnv(AppSpawnMgr *content, AppSpawningCtx *property) ret = SetAppAccessToken(content, property); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret); - // set isolate dir for custom sandbox by ioctl - if ((IsAppSpawnMode(content) || IsNativeSpawnMode(content)) && - CheckAppMsgFlagsSet(property, APP_FLAGS_CUSTOM_SANDBOX)) { - ret = SetIsolateDirForCustomSandbox(property); - APPSPAWN_CHECK_ONLY_LOG(ret == 0, "Failed to set isolate dir for custom sandbox, ret %{public}d", ret); + if ((IsAppSpawnMode(content) || IsNativeSpawnMode(content))) { + ret = SetIsolateDir(property); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "Failed to set isolate dir, ret %{public}d", ret); } ret = SpawnSetPreInstalledFlag(property); diff --git a/test/mock/app_spawn_stub.h b/test/mock/app_spawn_stub.h index 61c87d262905e70244bdf1c8f2c1d2a7a3e93e65..c9009860f5c5b0c0fec9900ad3334e4cd6dc6c87 100644 --- a/test/mock/app_spawn_stub.h +++ b/test/mock/app_spawn_stub.h @@ -102,7 +102,7 @@ void SetDeveloperMode(bool mode); int LoadPermission(AppSpawnClientType type); void DeletePermission(AppSpawnClientType type); int SetProcessName(const AppSpawnMgr *content, const AppSpawningCtx *property); -int SetIsolateDirForCustomSandbox(const AppSpawningCtx *property); +int SetIsolateDir(const AppSpawningCtx *property); int SetFdEnv(AppSpawnMgr *content, AppSpawningCtx *property); int PreLoadEnablePidNs(AppSpawnMgr *content); int NsInitFunc(); diff --git a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp index 2dff1ef80dafa5f63f1c449181594da45c6e67a6..56cfd9968fb2fd5b533fd03926643a78e4df2dba 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp @@ -797,7 +797,7 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_SetIsolateDir, TestSize.Level0) APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break); property = g_testHelper.GetAppProperty(clientHandle, reqHandle); APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break); - ret = SetIsolateDirForCustomSandbox(property); + ret = SetIsolateDir(property); } while (0); DeleteAppSpawningCtx(property); AppSpawnClientDestroy(clientHandle);