-
Notifications
You must be signed in to change notification settings - Fork 192
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
Storage cleanup #670
Storage cleanup #670
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (c) 2023, Linaro Limited | ||
*/ | ||
|
||
#include <err.h> | ||
#include <ta_storage.h> | ||
#include <tee_client_api.h> | ||
#include <stdlib.h> | ||
#include <util.h> | ||
|
||
#include "clear_storage.h" | ||
|
||
static int clear_storage_for_ta(TEEC_UUID *uuid) | ||
{ | ||
TEEC_Result res = TEEC_ERROR_GENERIC; | ||
TEEC_Context ctx = { }; | ||
TEEC_Session sess = { }; | ||
TEEC_Operation op = { }; | ||
uint32_t eo = 0; | ||
|
||
res = TEEC_InitializeContext(NULL, &ctx); | ||
if (res) | ||
errx(EXIT_FAILURE, "TEEC_InitializeContext: %#"PRIx32, res); | ||
|
||
res = TEEC_OpenSession(&ctx, &sess, uuid, TEEC_LOGIN_PUBLIC, NULL, | ||
NULL, &eo); | ||
if (res) | ||
errx(EXIT_FAILURE, | ||
"TEEC_OpenSession: res %#"PRIx32" err_orig %#"PRIx32, | ||
res, eo); | ||
|
||
op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, | ||
TEEC_NONE); | ||
res = TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_CLEAR_STORAGE, &op, &eo); | ||
if (res) | ||
errx(EXIT_FAILURE, | ||
"TEEC_InvokeCommand: res %#"PRIx32" err_orig %#"PRIx32, | ||
res, eo); | ||
|
||
TEEC_CloseSession(&sess); | ||
TEEC_FinalizeContext(&ctx); | ||
return 0; | ||
} | ||
|
||
int clear_storage(void) | ||
{ | ||
TEEC_UUID uuid[] = { TA_STORAGE_UUID, TA_STORAGE2_UUID }; | ||
size_t i = 0; | ||
int res = 0; | ||
|
||
for (i = 0; i < ARRAY_SIZE(uuid); i++) { | ||
res = clear_storage_for_ta(uuid + i); | ||
if (res) | ||
break; | ||
} | ||
return res; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (c) 2023, Linaro Limited | ||
*/ | ||
|
||
#ifndef CLEAR_STORAGE_H | ||
#define CLEAR_STORAGE_H | ||
|
||
int clear_storage(void); | ||
|
||
#endif /*CLEAR_STORAGE_H*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
#include "ta_storage.h" | ||
|
||
#include <tee_api.h> | ||
#include <tee_api_defines_extensions.h> | ||
#include <trace.h> | ||
#include <user_ta_header_defines.h> | ||
|
||
#define ASSERT_PARAM_TYPE(pt) \ | ||
do { \ | ||
|
@@ -662,3 +664,77 @@ TEE_Result ta_storage_cmd_get_obj_info(uint32_t param_types, | |
|
||
return res; | ||
} | ||
|
||
static TEE_Result clear_storage(uint32_t storage_id) | ||
{ | ||
TEE_ObjectEnumHandle oe = TEE_HANDLE_NULL; | ||
TEE_Result enum_res = TEE_ERROR_GENERIC; | ||
TEE_ObjectHandle o = TEE_HANDLE_NULL; | ||
TEE_Result res = TEE_ERROR_GENERIC; | ||
TEE_UUID uuid = TA_UUID; | ||
TEE_ObjectInfo oi = { }; | ||
size_t obj_id_sz = 0; | ||
void *obj_id = NULL; | ||
size_t i = 0; | ||
|
||
IMSG("Clearing TA storage (UUID: %pUl, storage ID: 0x%x)", | ||
(void *)&uuid, storage_id); | ||
res = TEE_AllocatePersistentObjectEnumerator(&oe); | ||
if (res) | ||
return res; | ||
res = TEE_StartPersistentObjectEnumerator(oe, storage_id); | ||
if (res == TEE_ERROR_ITEM_NOT_FOUND) { | ||
IMSG("No object found"); | ||
res = TEE_SUCCESS; | ||
goto out; | ||
} | ||
if (res) | ||
goto out; | ||
obj_id = TEE_Malloc(TEE_OBJECT_ID_MAX_LEN, 0); | ||
if (!obj_id) { | ||
res = TEE_ERROR_OUT_OF_MEMORY; | ||
goto out; | ||
} | ||
|
||
while (true) { | ||
enum_res = TEE_GetNextPersistentObject(oe, &oi, obj_id, | ||
&obj_id_sz); | ||
if (enum_res == TEE_ERROR_ITEM_NOT_FOUND) | ||
break; | ||
if (enum_res) { | ||
res = enum_res; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case relates to an unexpected error. I think it should be reported by the TA as its storage may not have been wiped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code updated to set |
||
} | ||
IMSG("Deleting persistent object #%zu", i); | ||
res = TEE_OpenPersistentObject(storage_id, obj_id, obj_id_sz, | ||
TEE_DATA_FLAG_ACCESS_WRITE_META, | ||
&o); | ||
if (res) | ||
break; | ||
TEE_CloseAndDeletePersistentObject1(o); | ||
i++; | ||
} | ||
|
||
out: | ||
TEE_FreePersistentObjectEnumerator(oe); | ||
TEE_Free(obj_id); | ||
return res; | ||
} | ||
|
||
TEE_Result ta_storage_cmd_clear_storage(uint32_t param_types, | ||
TEE_Param params[4]) | ||
{ | ||
uint32_t id[] = { TEE_STORAGE_PRIVATE_REE, TEE_STORAGE_PRIVATE_RPMB }; | ||
TEE_Result res = TEE_ERROR_GENERIC; | ||
size_t i = 0; | ||
|
||
(void)param_types; | ||
(void)params; | ||
|
||
for (i = 0; i < sizeof(id) / sizeof(id[0]); i++) { | ||
res = clear_storage(id[i]); | ||
if (res) | ||
break; | ||
} | ||
return res; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should set
res = TEE_ERROR_OUT_OF_MEMORY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.