diff --git a/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp b/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp index f888798..26a9303 100644 --- a/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp +++ b/kernel_liteos_a-master/testsuites/unittest/security/capability/smoke/cap_test_001.cpp @@ -53,6 +53,7 @@ static void Child() while (i--) { sleep(1); } + //sleep for 10 second and exit; exit(0); } @@ -62,20 +63,22 @@ static int TestChild(VOID) struct __user_cap_data_struct capdata[CAP_NUM]; struct __user_cap_data_struct capdatac[CAP_NUM]; struct timespec tp; - int ret; - + int ret + //originalize struct (void)memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); (void)memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, CAP_NUM * sizeof(struct __user_cap_data_struct)); capdata[0].permitted = 0xffffffff; capdata[1].permitted = 0xffffffff; capheader.version = _LINUX_CAPABILITY_VERSION_3; + //set capbility to effective capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETPCAP); capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SETUID); capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_KILL); capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_TIME); capdata[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); - ret = capset(&capheader, &capdata[0]); + //use capset to check and get info + ret = capset(&capheader, &capdata[0]); ICUNIT_ASSERT_EQUAL(ret, 0, ret); ret = capget(&capheader, &capdatac[0]); ICUNIT_ASSERT_EQUAL(ret, 0, ret); @@ -115,8 +118,8 @@ static int TestChild(VOID) printf("e %d,p %d\n", capdatac[0].effective, capdatac[0].permitted); } capheader.pid = 0; - - int pid = fork(); + //try reset UID + int pid = fork(); if (pid == 0) { ret = setuid(CHANGE_CHILD_UID); ICUNIT_ASSERT_EQUAL(ret, 0, ret); @@ -160,6 +163,7 @@ static int TestCase(VOID) int status = 0; pid_t pid = fork(); ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); + if (pid == 0) { ret = TestChild(); exit(__LINE__);