Skip to content

Commit

Permalink
Fix Storage TA ABI TEE_ObjectInfo
Browse files Browse the repository at this point in the history
With the updated types for GP 1.3 TEE_ObjectInfo contains elements with
the type size_t. If xtest is built for AArch64 while the storage TA is
built for AArch32 the ABI will become incompatible. Fix this by adding
struct ta_storage_obj_info with fixed width integers only and use that
in the TA ABI used by xtest.

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
jenswi-linaro authored and jforissier committed Mar 29, 2023
1 parent c0a6172 commit fec6bea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
33 changes: 21 additions & 12 deletions host/xtest/regression_6000.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,33 @@ static TEEC_Result fs_reset_obj(TEEC_Session *sess, uint32_t obj)
}

static TEEC_Result fs_get_obj_info(TEEC_Session *sess, uint32_t obj,
void *obj_info, size_t info_size)
TEE_ObjectInfo *obj_info)
{
TEEC_Result res = TEEC_SUCCESS;
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
struct ta_storage_obj_info oi = { };
uint32_t org = 0;

op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
TEEC_MEMREF_TEMP_OUTPUT,
TEEC_NONE, TEEC_NONE);

op.params[0].value.a = obj;
op.params[1].tmpref.buffer = obj_info;
op.params[1].tmpref.size = info_size;
op.params[1].tmpref.buffer = &oi;
op.params[1].tmpref.size = sizeof(oi);

res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_GET_OBJ_INFO, &op, &org);
if (!res) {
obj_info->objectType = oi.object_type;
obj_info->objectSize = oi.object_size;
obj_info->maxObjectSize = oi.max_object_size;
obj_info->objectUsage = oi.object_usage;
obj_info->dataSize = oi.data_size;
obj_info->dataPosition = oi.data_position;
obj_info->handleFlags = oi.handle_flags;
}

return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_GET_OBJ_INFO, &op, &org);
return res;
}

/* Record availability of all secure storage types at runtime */
Expand Down Expand Up @@ -1826,8 +1839,7 @@ static void xtest_tee_test_6017_single(ADBG_Case_t *c, uint32_t storage_id)
goto exit;

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
fs_get_obj_info(&sess, obj, &obj_info1,
sizeof(TEE_ObjectInfo))))
fs_get_obj_info(&sess, obj, &obj_info1)))
goto exit;

if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
Expand All @@ -1839,8 +1851,7 @@ static void xtest_tee_test_6017_single(ADBG_Case_t *c, uint32_t storage_id)
goto exit;

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
fs_get_obj_info(&sess, obj, &obj_info2,
sizeof(TEE_ObjectInfo))))
fs_get_obj_info(&sess, obj, &obj_info2)))
goto exit;

if (!ADBG_EXPECT_COMPARE_UNSIGNED(c,
Expand Down Expand Up @@ -1899,8 +1910,7 @@ static void xtest_tee_test_6018_single(ADBG_Case_t *c, uint32_t storage_id)
}

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
fs_get_obj_info(&sess, obj, &obj_info1,
sizeof(TEE_ObjectInfo))))
fs_get_obj_info(&sess, obj, &obj_info1)))
goto exit;

if (!ADBG_EXPECT_COMPARE_UNSIGNED(c,
Expand All @@ -1917,8 +1927,7 @@ static void xtest_tee_test_6018_single(ADBG_Case_t *c, uint32_t storage_id)
goto exit;

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
fs_get_obj_info(&sess, obj, &obj_info2,
sizeof(TEE_ObjectInfo))))
fs_get_obj_info(&sess, obj, &obj_info2)))
goto exit;

if (!ADBG_EXPECT_COMPARE_UNSIGNED(c,
Expand Down
10 changes: 10 additions & 0 deletions ta/include/ta_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
#define TA_STORAGE2_UUID { 0x731e279e, 0xaafb, 0x4575, \
{ 0xa7, 0x71, 0x38, 0xca, 0xa6, 0xf0, 0xcc, 0xa6 } }

struct ta_storage_obj_info {
uint32_t object_type;
uint32_t object_size;
uint32_t max_object_size;
uint32_t object_usage;
uint32_t data_size;
uint32_t data_position;
uint32_t handle_flags;
};

#define TA_STORAGE_CMD_OPEN 0
#define TA_STORAGE_CMD_CLOSE 1
#define TA_STORAGE_CMD_READ 2
Expand Down
14 changes: 11 additions & 3 deletions ta/storage/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ TEE_Result ta_storage_cmd_get_obj_info(uint32_t param_types,
TEE_Param params[4])
{
TEE_Result res = TEE_ERROR_GENERIC;
struct ta_storage_obj_info oi = { };
TEE_ObjectInfo info = { };
TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a);

Expand All @@ -644,12 +645,19 @@ TEE_Result ta_storage_cmd_get_obj_info(uint32_t param_types,
TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE));

if (params[1].memref.size < sizeof(info))
if (params[1].memref.size < sizeof(oi))
return TEE_ERROR_SHORT_BUFFER;
res = TEE_GetObjectInfo1(o, &info);
if (!res) {
params[1].memref.size = sizeof(info);
TEE_MemMove(params[1].memref.buffer, &info, sizeof(info));
params[1].memref.size = sizeof(oi);
oi.object_type = info.objectType;
oi.object_size = info.objectSize;
oi.max_object_size = info.maxObjectSize;
oi.object_usage = info.objectUsage;
oi.data_size = info.dataSize;
oi.data_position = info.dataPosition;
oi.handle_flags = info.handleFlags;
TEE_MemMove(params[1].memref.buffer, &oi, sizeof(oi));
}

return res;
Expand Down

0 comments on commit fec6bea

Please sign in to comment.