Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restric usage #715

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions host/xtest/regression_6000.c
Original file line number Diff line number Diff line change
Expand Up @@ -2254,3 +2254,65 @@ static void xtest_tee_test_6020_single(ADBG_Case_t *c, uint32_t storage_id)
DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6020)
ADBG_CASE_DEFINE(regression, 6020, xtest_tee_test_6020,
"Object IDs in SHM (negative)");

static void xtest_tee_test_6021_single(ADBG_Case_t *c, uint32_t storage_id)
{
const uint32_t flags = TEE_DATA_FLAG_ACCESS_READ |
TEE_DATA_FLAG_ACCESS_WRITE |
TEE_DATA_FLAG_ACCESS_WRITE_META;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEE_DATA_FLAG_OVERWRITE to ensure object is destroyed and recreated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll add it to the create call.

TEEC_Result res = TEEC_ERROR_GENERIC;
TEE_ObjectInfo obj_info = { };
uint32_t ou = 0xffffffff;
TEEC_Session sess = { };
uint32_t orig = 0;
uint32_t obj = 0;

res = xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
return;

res = fs_create(&sess, file_01, sizeof(file_01),
flags | TEE_DATA_FLAG_OVERWRITE, 0,
data_00, sizeof(data_00), &obj, storage_id);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;

res = fs_get_obj_info(&sess, obj, &obj_info);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;
ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, ou);

ou &= ~TEE_USAGE_EXTRACTABLE;
res = fs_restrict_usage(&sess, obj, ou);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;

res = fs_get_obj_info(&sess, obj, &obj_info);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;
ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, ou);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto exit here on failure I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test has failed at this point, but it's not completely useless to open a new session, reopen the object, and check once more. The test is stable even on errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj));
TEEC_CloseSession(&sess);

res = xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
return;

res = fs_open(&sess, file_01, sizeof(file_01), flags, &obj, storage_id);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;

res = fs_get_obj_info(&sess, obj, &obj_info);
if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
goto exit;
ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, ou);

exit:
ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj));
TEEC_CloseSession(&sess);
return;
}
DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6021)
ADBG_CASE_DEFINE(regression, 6021, xtest_tee_test_6021,
"Modify and check persistent object usage");
4 changes: 2 additions & 2 deletions ta/storage/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ TEE_Result ta_storage_cmd_key_in_persistent(uint32_t param_types,
result = check_obj(&keyInfo, &keyInfo2);
if (result != TEE_SUCCESS) {
EMSG("keyInfo and keyInfo2 are different");
goto cleanup2;
goto cleanup3;
}

TEE_CloseObject(persistent_key);
Expand All @@ -504,7 +504,7 @@ TEE_Result ta_storage_cmd_key_in_persistent(uint32_t param_types,
result = check_obj(&keyInfo3, &keyInfo2);
if (result != TEE_SUCCESS) {
EMSG("keyInfo2 and keyInfo3 are different");
goto cleanup2;
goto cleanup3;
}

result = TEE_AllocateOperation(&encrypt_op, alg, TEE_MODE_ENCRYPT,
Expand Down