提交 4d341b1a 编写于 作者: C cheng_jinsong

fix appspawn check

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 4fb1cf39
......@@ -300,18 +300,39 @@ INIT_LOCAL_API int OpenWorkSpace(uint32_t index, int readOnly)
}
int ret = 0;
uint32_t rwSpaceLock = ATOMIC_LOAD_EXPLICIT(&workSpace->rwSpaceLock, MEMORY_ORDER_ACQUIRE);
if (rwSpaceLock == 1) {
if (rwSpaceLock & WORKSPACE_STATUS_IN_PROCESS) {
PARAM_LOGW("Workspace %s in init", workSpace->fileName);
return -1;
}
ATOMIC_STORE_EXPLICIT(&workSpace->rwSpaceLock, 1, MEMORY_ORDER_RELEASE);
ATOMIC_STORE_EXPLICIT(&workSpace->rwSpaceLock, rwSpaceLock | WORKSPACE_STATUS_IN_PROCESS, MEMORY_ORDER_RELEASE);
if (workSpace->area == NULL) {
ret = InitWorkSpace(workSpace, readOnly, workSpace->spaceSize);
if (ret != 0) {
PARAM_LOGE("Forbid to open workspace for %s error %d", workSpace->fileName, errno);
}
#ifndef PARAM_SUPPORT_SELINUX
}
ATOMIC_STORE_EXPLICIT(&workSpace->rwSpaceLock, rwSpaceLock & ~WORKSPACE_STATUS_IN_PROCESS, MEMORY_ORDER_RELEASE);
#else
} else if (readOnly) {
if ((rwSpaceLock & WORKSPACE_STATUS_VALID) == WORKSPACE_STATUS_VALID) {
ret = 0;
} else if ((paramSpace->flags & WORKSPACE_FLAGS_NEED_ACCESS) == WORKSPACE_FLAGS_NEED_ACCESS) {
char buffer[FILENAME_LEN_MAX] = {0};
int size = PARAM_SPRINTF(buffer, sizeof(buffer), "%s/%s", PARAM_STORAGE_PATH, workSpace->fileName);
if (size > 0 && access(buffer, R_OK) == 0) {
PARAM_LOGW("Open workspace %s access ok ", workSpace->fileName);
rwSpaceLock |= WORKSPACE_STATUS_VALID;
ret = 0;
} else {
ret = -1;
PARAM_LOGE("Forbid to open workspace for %s error %d", workSpace->fileName, errno);
rwSpaceLock &= ~WORKSPACE_STATUS_VALID;
}
}
}
ATOMIC_STORE_EXPLICIT(&workSpace->rwSpaceLock, 0, MEMORY_ORDER_RELEASE);
ATOMIC_STORE_EXPLICIT(&workSpace->rwSpaceLock, rwSpaceLock & ~WORKSPACE_STATUS_IN_PROCESS, MEMORY_ORDER_RELEASE);
#endif
return ret;
}
......@@ -428,30 +449,6 @@ STATIC_INLINE int DacCheckParamPermission(const ParamLabelIndex *labelIndex,
}
#ifdef PARAM_SUPPORT_SELINUX
STATIC_INLINE int IsWorkSpaceReady(WorkSpace *workSpace)
{
if (workSpace == NULL) {
return -1;
}
int ret = -1;
uint32_t rwSpaceLock = ATOMIC_LOAD_EXPLICIT(&workSpace->rwSpaceLock, MEMORY_ORDER_ACQUIRE);
if (rwSpaceLock == 1) {
return ret;
}
if (workSpace->area != NULL) {
if ((g_paramWorkSpace.flags & WORKSPACE_FLAGS_NEED_ACCESS) == WORKSPACE_FLAGS_NEED_ACCESS) {
char buffer[FILENAME_LEN_MAX] = {0};
int size = PARAM_SPRINTF(buffer, sizeof(buffer), "%s/%s", PARAM_STORAGE_PATH, workSpace->fileName);
if (size > 0 && access(buffer, R_OK) == 0) {
ret = 0;
}
} else {
ret = 0;
}
}
return ret;
}
STATIC_INLINE const char *GetSelinuxContent(const char *name)
{
SelinuxSpace *selinuxSpace = &g_paramWorkSpace.selinuxSpace;
......@@ -481,9 +478,6 @@ STATIC_INLINE int SelinuxCheckParamPermission(const ParamLabelIndex *labelIndex,
#ifdef STARTUP_INIT_TEST
return selinuxSpace->readParamCheck(name);
#endif
if (IsWorkSpaceReady(labelIndex->workspace) == 0) {
return DAC_RESULT_PERMISSION;
}
ret = OpenWorkSpace(labelIndex->selinuxLabelIndex, 1);
}
if (ret != 0) {
......
......@@ -29,6 +29,9 @@ extern "C" {
#endif
#endif
#define WORKSPACE_STATUS_IN_PROCESS 0x01
#define WORKSPACE_STATUS_VALID 0x02
#ifndef PARAM_BASE
#define PARAM_SPRINTF(buffer, buffSize, format, ...) \
snprintf_s((buffer), (buffSize), (buffSize) - 1, (format), ##__VA_ARGS__)
......
......@@ -55,7 +55,7 @@ INIT_LOCAL_API WorkSpace *GetWorkSpace(uint32_t labelIndex)
return NULL;
}
uint32_t rwSpaceLock = ATOMIC_LOAD_EXPLICIT(&workSpace->rwSpaceLock, MEMORY_ORDER_ACQUIRE);
if (rwSpaceLock == 1) {
if (rwSpaceLock & WORKSPACE_STATUS_IN_PROCESS) {
return NULL;
}
if (workSpace->area != NULL) {
......
......@@ -47,7 +47,10 @@ typedef enum {
#define PARAM_ENTRY(ptr, type, member) (type *)((char *)(ptr)-offsetof(type, member))
#define IS_READY_ONLY(name) \
((strncmp((name), "const.", strlen("const.")) == 0) || (strncmp((name), "ro.", strlen("ro.")) == 0))
((strncmp((name), "const.", strlen("const.")) == 0) || \
(strncmp((name), "ro.", strlen("ro.")) == 0) || \
(strncmp((name), "ohos.boot.", strlen("ohos.boot.")) == 0))
#define PARAM_PERSIST_PREFIX "persist."
#define SYS_POWER_CTRL "ohos.startup.powerctrl="
......
......@@ -28,7 +28,6 @@ using namespace testing::ext;
using namespace std;
extern "C" {
int IsWorkSpaceReady(WorkSpace *workSpace);
void ParamWorBaseLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
static void OnClose(const TaskHandle taskHandle)
{
......@@ -663,19 +662,5 @@ HWTEST_F(ParamUnitTest, TestParamCache, TestSize.Level0)
EXPECT_EQ(valueChange, 1);
CachedParameterDestroy(cacheHandle3);
}
#ifdef PARAM_SUPPORT_SELINUX
HWTEST_F(ParamUnitTest, TestInitParameterClient, TestSize.Level0)
{
InitParameterClient();
WorkSpace *workspace = GetWorkSpace(0);
int ret = IsWorkSpaceReady(workspace);
EXPECT_EQ(ret, 0);
ret = IsWorkSpaceReady(NULL);
EXPECT_NE(ret, 0);
workspace = GetWorkSpace(1);
ret = IsWorkSpaceReady(workspace);
EXPECT_EQ(ret, 0);
}
#endif
#endif
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册