Etienne Carriere | 7514117 | 2020-05-16 11:58:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 4 | * All rights reserved. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include "storage.h" |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 8 | #include "ta_storage.h" |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 9 | |
| 10 | #include <tee_api.h> |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 11 | #include <trace.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 12 | |
| 13 | #define ASSERT_PARAM_TYPE(pt) \ |
| 14 | do { \ |
| 15 | if ((pt) != param_types) \ |
| 16 | return TEE_ERROR_BAD_PARAMETERS; \ |
| 17 | } while (0) |
| 18 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 19 | #define VAL2HANDLE(v) (void *)(uintptr_t)(v) |
| 20 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 21 | TEE_Result ta_storage_cmd_open(uint32_t command, |
| 22 | uint32_t param_types, TEE_Param params[4]) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 23 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 24 | TEE_Result res = TEE_ERROR_GENERIC; |
| 25 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
| 26 | void *object_id = NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 27 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 28 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 29 | (TEE_PARAM_TYPE_MEMREF_INPUT, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 30 | TEE_PARAM_TYPE_VALUE_INOUT, |
| 31 | TEE_PARAM_TYPE_VALUE_INPUT, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 32 | TEE_PARAM_TYPE_NONE)); |
| 33 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 34 | switch (command) { |
| 35 | case TA_STORAGE_CMD_OPEN: |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 36 | if (params[0].memref.buffer) { |
| 37 | object_id = TEE_Malloc(params[0].memref.size, 0); |
| 38 | if (!object_id) |
| 39 | return TEE_ERROR_OUT_OF_MEMORY; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 40 | |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 41 | TEE_MemMove(object_id, params[0].memref.buffer, |
| 42 | params[0].memref.size); |
| 43 | } |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 44 | break; |
| 45 | case TA_STORAGE_CMD_OPEN_ID_IN_SHM: |
| 46 | object_id = params[0].memref.buffer; |
| 47 | break; |
| 48 | default: |
| 49 | return TEE_ERROR_NOT_SUPPORTED; |
| 50 | } |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 51 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 52 | res = TEE_OpenPersistentObject(params[2].value.a, |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 53 | object_id, params[0].memref.size, |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 54 | params[1].value.a, &o); |
| 55 | |
| 56 | params[1].value.b = (uintptr_t)o; |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 57 | |
| 58 | if (command == TA_STORAGE_CMD_OPEN) |
| 59 | TEE_Free(object_id); |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 60 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 61 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 64 | TEE_Result ta_storage_cmd_create(uint32_t command, |
| 65 | uint32_t param_types, TEE_Param params[4]) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 66 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 67 | TEE_Result res = TEE_ERROR_GENERIC; |
| 68 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
| 69 | void *object_id = NULL; |
| 70 | TEE_ObjectHandle ref_handle = TEE_HANDLE_NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 71 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 72 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 73 | (TEE_PARAM_TYPE_MEMREF_INPUT, |
| 74 | TEE_PARAM_TYPE_VALUE_INOUT, |
| 75 | TEE_PARAM_TYPE_VALUE_INPUT, |
| 76 | TEE_PARAM_TYPE_MEMREF_INPUT)); |
| 77 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 78 | switch (command) { |
| 79 | case TA_STORAGE_CMD_CREATE: |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 80 | if (params[0].memref.buffer) { |
| 81 | object_id = TEE_Malloc(params[0].memref.size, 0); |
| 82 | if (!object_id) |
| 83 | return TEE_ERROR_OUT_OF_MEMORY; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 84 | |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 85 | TEE_MemMove(object_id, params[0].memref.buffer, |
| 86 | params[0].memref.size); |
| 87 | } |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 88 | break; |
| 89 | case TA_STORAGE_CMD_CREATE_ID_IN_SHM: |
| 90 | object_id = params[0].memref.buffer; |
| 91 | break; |
| 92 | default: |
| 93 | return TEE_ERROR_NOT_SUPPORTED; |
| 94 | } |
| 95 | |
| 96 | ref_handle = (TEE_ObjectHandle)(uintptr_t)params[2].value.a; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 97 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 98 | res = TEE_CreatePersistentObject(params[2].value.b, |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 99 | object_id, params[0].memref.size, |
| 100 | params[1].value.a, ref_handle, |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 101 | params[3].memref.buffer, |
| 102 | params[3].memref.size, &o); |
| 103 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 104 | if (command == TA_STORAGE_CMD_CREATE) |
| 105 | TEE_Free(object_id); |
| 106 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 107 | params[1].value.b = (uintptr_t)o; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 108 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 109 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 112 | TEE_Result ta_storage_cmd_create_overwrite(uint32_t command, |
| 113 | uint32_t param_types, |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 114 | TEE_Param params[4]) |
| 115 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 116 | TEE_Result res = TEE_ERROR_GENERIC; |
Cedric Auger | 3ad6b8a | 2019-09-11 16:38:42 +0200 | [diff] [blame] | 117 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 118 | void *object_id = NULL; |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 119 | |
| 120 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 121 | (TEE_PARAM_TYPE_MEMREF_INPUT, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 122 | TEE_PARAM_TYPE_VALUE_INPUT, |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 123 | TEE_PARAM_TYPE_NONE, |
| 124 | TEE_PARAM_TYPE_NONE)); |
| 125 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 126 | switch (command) { |
| 127 | case TA_STORAGE_CMD_CREATE_OVERWRITE: |
| 128 | object_id = TEE_Malloc(params[0].memref.size, 0); |
| 129 | if (!object_id) |
| 130 | return TEE_ERROR_OUT_OF_MEMORY; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 131 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 132 | TEE_MemMove(object_id, params[0].memref.buffer, |
| 133 | params[0].memref.size); |
| 134 | break; |
| 135 | case TA_STORAGE_CMD_CREATEOVER_ID_IN_SHM: |
| 136 | object_id = params[0].memref.buffer; |
| 137 | break; |
| 138 | default: |
| 139 | return TEE_ERROR_NOT_SUPPORTED; |
| 140 | } |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 141 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 142 | res = TEE_CreatePersistentObject(params[1].value.a, |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 143 | object_id, params[0].memref.size, |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 144 | TEE_DATA_FLAG_OVERWRITE, |
Cedric Auger | 3ad6b8a | 2019-09-11 16:38:42 +0200 | [diff] [blame] | 145 | NULL, NULL, 0, &o); |
| 146 | TEE_CloseObject(o); |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 147 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 148 | if (command == TA_STORAGE_CMD_CREATE_OVERWRITE) |
| 149 | TEE_Free(object_id); |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 150 | |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 151 | return res; |
| 152 | } |
| 153 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 154 | TEE_Result ta_storage_cmd_close(uint32_t param_types, TEE_Param params[4]) |
| 155 | { |
| 156 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 157 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 158 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 159 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 160 | TEE_CloseObject((TEE_ObjectHandle)(uintptr_t)params[0].value.a); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 161 | |
| 162 | return TEE_SUCCESS; |
| 163 | } |
| 164 | |
| 165 | TEE_Result ta_storage_cmd_read(uint32_t param_types, TEE_Param params[4]) |
| 166 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 167 | TEE_ObjectHandle o = VAL2HANDLE(params[1].value.a); |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 168 | TEE_Result res = TEE_SUCCESS; |
Jens Wiklander | e1634fa | 2022-12-12 12:59:28 +0100 | [diff] [blame] | 169 | size_t sz = 0; |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 170 | void *b0 = NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 171 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 172 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 173 | (TEE_PARAM_TYPE_MEMREF_OUTPUT, |
| 174 | TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, |
| 175 | TEE_PARAM_TYPE_NONE)); |
| 176 | |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 177 | b0 = TEE_Malloc(params[0].memref.size, 0); |
| 178 | if (!b0) |
| 179 | return TEE_ERROR_OUT_OF_MEMORY; |
| 180 | |
Jens Wiklander | e1634fa | 2022-12-12 12:59:28 +0100 | [diff] [blame] | 181 | sz = params[1].value.b; |
| 182 | res = TEE_ReadObjectData(o, b0, params[0].memref.size, &sz); |
| 183 | params[1].value.b = sz; |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 184 | if (!res) |
| 185 | TEE_MemMove(params[0].memref.buffer, b0, params[0].memref.size); |
| 186 | TEE_Free(b0); |
| 187 | |
| 188 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | TEE_Result ta_storage_cmd_write(uint32_t param_types, TEE_Param params[4]) |
| 192 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 193 | TEE_ObjectHandle o = VAL2HANDLE(params[1].value.a); |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 194 | TEE_Result res = TEE_SUCCESS; |
| 195 | void *b0 = NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 196 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 197 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 198 | (TEE_PARAM_TYPE_MEMREF_INPUT, |
| 199 | TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 200 | TEE_PARAM_TYPE_NONE)); |
| 201 | |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 202 | b0 = TEE_Malloc(params[0].memref.size, 0); |
| 203 | if (!b0) |
| 204 | return TEE_ERROR_OUT_OF_MEMORY; |
| 205 | TEE_MemMove(b0, params[0].memref.buffer, params[0].memref.size); |
| 206 | |
| 207 | res = TEE_WriteObjectData(o, b0, params[0].memref.size); |
| 208 | TEE_Free(b0); |
| 209 | |
| 210 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | TEE_Result ta_storage_cmd_seek(uint32_t param_types, TEE_Param params[4]) |
| 214 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 215 | TEE_Result res = TEE_ERROR_GENERIC; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 216 | TEE_ObjectInfo info; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 217 | TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a); |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 218 | int32_t offs = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 219 | |
| 220 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 221 | (TEE_PARAM_TYPE_VALUE_INPUT, |
| 222 | TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, |
| 223 | TEE_PARAM_TYPE_NONE)); |
| 224 | |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 225 | offs = *(int32_t *)¶ms[0].value.b; |
| 226 | res = TEE_SeekObjectData(o, offs, params[1].value.a); |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 227 | if (res != TEE_SUCCESS) |
| 228 | return res; |
| 229 | res = TEE_GetObjectInfo1(o, &info); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 230 | |
| 231 | params[1].value.b = info.dataPosition; |
| 232 | |
| 233 | return res; |
| 234 | } |
| 235 | |
| 236 | TEE_Result ta_storage_cmd_unlink(uint32_t param_types, TEE_Param params[4]) |
| 237 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 238 | TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a); |
| 239 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 240 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 241 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 242 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 243 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 244 | TEE_CloseAndDeletePersistentObject1(o); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 245 | |
| 246 | return TEE_SUCCESS; |
| 247 | } |
| 248 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 249 | TEE_Result ta_storage_cmd_rename(uint32_t command, uint32_t param_types, |
| 250 | TEE_Param params[4]) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 251 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 252 | TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a); |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 253 | void *object_id = NULL; |
| 254 | TEE_Result res = TEE_ERROR_GENERIC; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 255 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 256 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 257 | (TEE_PARAM_TYPE_VALUE_INPUT, |
| 258 | TEE_PARAM_TYPE_MEMREF_INPUT, TEE_PARAM_TYPE_NONE, |
| 259 | TEE_PARAM_TYPE_NONE)); |
| 260 | |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 261 | switch (command) { |
| 262 | case TA_STORAGE_CMD_RENAME: |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 263 | if (params[0].memref.buffer) { |
| 264 | object_id = TEE_Malloc(params[1].memref.size, 0); |
| 265 | if (!object_id) |
| 266 | return TEE_ERROR_OUT_OF_MEMORY; |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 267 | |
Jerome Forissier | c7a7373 | 2022-02-23 14:46:00 +0100 | [diff] [blame] | 268 | TEE_MemMove(object_id, params[1].memref.buffer, |
| 269 | params[1].memref.size); |
| 270 | } |
Etienne Carriere | 294ffbd | 2018-04-26 14:20:35 +0200 | [diff] [blame] | 271 | break; |
| 272 | case TA_STORAGE_CMD_RENAME_ID_IN_SHM: |
| 273 | object_id = params[1].memref.buffer; |
| 274 | break; |
| 275 | default: |
| 276 | return TEE_ERROR_NOT_SUPPORTED; |
| 277 | } |
| 278 | |
| 279 | res = TEE_RenamePersistentObject(o, object_id, params[1].memref.size); |
| 280 | |
| 281 | if (command == TA_STORAGE_CMD_RENAME) |
| 282 | TEE_Free(object_id); |
Etienne Carriere | 9811a80 | 2018-02-16 16:11:42 +0100 | [diff] [blame] | 283 | |
| 284 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | TEE_Result ta_storage_cmd_trunc(uint32_t param_types, TEE_Param params[4]) |
| 288 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 289 | TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a); |
| 290 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 291 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 292 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 293 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 294 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 295 | return TEE_TruncateObjectData(o, params[0].value.b); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | TEE_Result ta_storage_cmd_alloc_enum(uint32_t param_types, TEE_Param params[4]) |
| 299 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 300 | TEE_Result res = TEE_ERROR_GENERIC; |
| 301 | TEE_ObjectEnumHandle oe = TEE_HANDLE_NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 302 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 303 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 304 | (TEE_PARAM_TYPE_VALUE_OUTPUT, TEE_PARAM_TYPE_NONE, |
| 305 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 306 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 307 | res = TEE_AllocatePersistentObjectEnumerator(&oe); |
| 308 | params[0].value.a = (uintptr_t)oe; |
| 309 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | TEE_Result ta_storage_cmd_free_enum(uint32_t param_types, TEE_Param params[4]) |
| 313 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 314 | TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a); |
| 315 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 316 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 317 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 318 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 319 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 320 | TEE_FreePersistentObjectEnumerator(oe); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 321 | return TEE_SUCCESS; |
| 322 | } |
| 323 | |
| 324 | TEE_Result ta_storage_cmd_reset_enum(uint32_t param_types, TEE_Param params[4]) |
| 325 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 326 | TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a); |
| 327 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 328 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 329 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 330 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 331 | |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 332 | TEE_ResetPersistentObjectEnumerator(oe); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 333 | return TEE_SUCCESS; |
| 334 | } |
| 335 | |
| 336 | TEE_Result ta_storage_cmd_start_enum(uint32_t param_types, TEE_Param params[4]) |
| 337 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 338 | TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a); |
| 339 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 340 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 341 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 342 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 343 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 344 | return TEE_StartPersistentObjectEnumerator(oe, params[0].value.b); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | TEE_Result ta_storage_cmd_next_enum(uint32_t param_types, TEE_Param params[4]) |
| 348 | { |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 349 | TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a); |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 350 | TEE_Result res = TEE_SUCCESS; |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 351 | TEE_ObjectInfo *obj = NULL; |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 352 | void *b2 = NULL; |
Jens Wiklander | c523159 | 2015-11-11 09:27:27 +0100 | [diff] [blame] | 353 | |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 354 | if (TEE_PARAM_TYPE_GET(param_types, 0) != TEE_PARAM_TYPE_VALUE_INPUT) |
| 355 | return TEE_ERROR_BAD_PARAMETERS; |
| 356 | if (TEE_PARAM_TYPE_GET(param_types, 2) != TEE_PARAM_TYPE_MEMREF_OUTPUT) |
| 357 | return TEE_ERROR_BAD_PARAMETERS; |
| 358 | if (TEE_PARAM_TYPE_GET(param_types, 3) != TEE_PARAM_TYPE_NONE) |
| 359 | return TEE_ERROR_BAD_PARAMETERS; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 360 | |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 361 | if (params[2].memref.size < TEE_OBJECT_ID_MAX_LEN) |
| 362 | return TEE_ERROR_SHORT_BUFFER; |
| 363 | |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 364 | if (TEE_PARAM_TYPE_GET(param_types, 1) == TEE_PARAM_TYPE_NONE) |
| 365 | obj = NULL; |
| 366 | else if (TEE_PARAM_TYPE_GET(param_types, 1) == |
| 367 | TEE_PARAM_TYPE_MEMREF_OUTPUT) { |
| 368 | if (params[1].memref.size < sizeof(TEE_ObjectInfo)) { |
| 369 | params[1].memref.size = sizeof(TEE_ObjectInfo); |
| 370 | return TEE_ERROR_SHORT_BUFFER; |
| 371 | } |
| 372 | params[1].memref.size = sizeof(TEE_ObjectInfo); |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 373 | obj = TEE_Malloc(sizeof(TEE_ObjectInfo), 0); |
| 374 | if (!obj) |
| 375 | return TEE_ERROR_OUT_OF_MEMORY; |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 376 | } else |
| 377 | return TEE_ERROR_BAD_PARAMETERS; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 378 | |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 379 | b2 = TEE_Malloc(params[2].memref.size, 0); |
| 380 | if (!b2) { |
| 381 | res = TEE_ERROR_OUT_OF_MEMORY; |
| 382 | goto out; |
| 383 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 384 | |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 385 | res = TEE_GetNextPersistentObject(oe, obj, b2, ¶ms[2].memref.size); |
| 386 | if (res) |
| 387 | goto out; |
| 388 | |
| 389 | TEE_MemMove(params[2].memref.buffer, b2, params[2].memref.size); |
| 390 | if (obj) |
| 391 | TEE_MemMove(params[1].memref.buffer, obj, sizeof(*obj)); |
| 392 | out: |
| 393 | TEE_Free(b2); |
| 394 | TEE_Free(obj); |
| 395 | |
| 396 | return res; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 397 | } |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 398 | |
| 399 | static TEE_Result check_obj(TEE_ObjectInfo *o1, TEE_ObjectInfo *o2) |
| 400 | { |
| 401 | if ((o1->objectType != o2->objectType) || |
Jens Wiklander | e1634fa | 2022-12-12 12:59:28 +0100 | [diff] [blame] | 402 | (o1->objectSize != o2->objectSize) || |
| 403 | (o1->maxObjectSize != o2->maxObjectSize) || |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 404 | (o1->objectUsage != o2->objectUsage)) |
| 405 | return TEE_ERROR_GENERIC; |
| 406 | return TEE_SUCCESS; |
| 407 | } |
| 408 | |
| 409 | TEE_Result ta_storage_cmd_key_in_persistent(uint32_t param_types, |
| 410 | TEE_Param params[4]) |
| 411 | { |
| 412 | TEE_Result result = TEE_SUCCESS; |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 413 | TEE_ObjectHandle transient_key = TEE_HANDLE_NULL; |
| 414 | TEE_ObjectHandle persistent_key = TEE_HANDLE_NULL; |
| 415 | TEE_ObjectHandle key = TEE_HANDLE_NULL; |
| 416 | TEE_OperationHandle encrypt_op = TEE_HANDLE_NULL; |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 417 | TEE_ObjectInfo keyInfo; |
| 418 | TEE_ObjectInfo keyInfo2; |
| 419 | TEE_ObjectInfo keyInfo3; |
| 420 | uint32_t alg = TEE_ALG_AES_CBC_NOPAD; |
| 421 | void *IV = NULL; |
| 422 | size_t IVlen = 16; |
| 423 | size_t key_size = 256; |
| 424 | uint32_t objectID = 1; |
| 425 | uint32_t flags = TEE_DATA_FLAG_ACCESS_READ | |
| 426 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 427 | TEE_DATA_FLAG_ACCESS_WRITE_META | |
| 428 | TEE_DATA_FLAG_SHARE_READ | |
| 429 | TEE_DATA_FLAG_SHARE_WRITE; |
| 430 | |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 431 | TEE_MemFill(&keyInfo, 0, sizeof(keyInfo)); |
| 432 | TEE_MemFill(&keyInfo2, 0, sizeof(keyInfo2)); |
| 433 | TEE_MemFill(&keyInfo3, 0, sizeof(keyInfo3)); |
| 434 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 435 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 436 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 437 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 438 | |
| 439 | result = TEE_AllocateTransientObject(TEE_TYPE_AES, key_size, |
| 440 | &transient_key); |
| 441 | if (result != TEE_SUCCESS) { |
| 442 | EMSG("Failed to Allocate transient object handle : 0x%x", |
| 443 | result); |
| 444 | goto cleanup1; |
| 445 | } |
| 446 | |
| 447 | result = TEE_GenerateKey(transient_key, key_size, NULL, 0); |
| 448 | if (result != TEE_SUCCESS) { |
| 449 | EMSG("Failed to generate a transient key: 0x%x", result); |
| 450 | goto cleanup2; |
| 451 | } |
| 452 | |
| 453 | TEE_GetObjectInfo1(transient_key, &keyInfo); |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 454 | result = TEE_CreatePersistentObject(params[0].value.a, |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 455 | &objectID, sizeof(objectID), |
| 456 | flags, transient_key, NULL, 0, |
| 457 | &persistent_key); |
| 458 | if (result != TEE_SUCCESS) { |
| 459 | EMSG("Failed to create a persistent key: 0x%x", result); |
| 460 | goto cleanup2; |
| 461 | } |
| 462 | |
| 463 | TEE_GetObjectInfo1(persistent_key, &keyInfo2); |
| 464 | result = check_obj(&keyInfo, &keyInfo2); |
| 465 | if (result != TEE_SUCCESS) { |
| 466 | EMSG("keyInfo and keyInfo2 are different"); |
| 467 | goto cleanup2; |
| 468 | } |
| 469 | |
Jens Wiklander | a75d2b9 | 2022-12-08 12:05:02 +0100 | [diff] [blame] | 470 | TEE_CloseAndDeletePersistentObject1(persistent_key); |
| 471 | |
| 472 | /* Transform the transient object into a persistent object */ |
| 473 | result = TEE_CreatePersistentObject(params[0].value.a, |
| 474 | &objectID, sizeof(objectID), |
| 475 | flags, transient_key, NULL, 0, |
| 476 | NULL); |
| 477 | if (result != TEE_SUCCESS) { |
| 478 | EMSG("Failed to create a persistent key: 0x%x", result); |
| 479 | goto cleanup2; |
| 480 | } |
| 481 | persistent_key = transient_key; |
| 482 | transient_key = TEE_HANDLE_NULL; |
| 483 | |
| 484 | TEE_GetObjectInfo1(persistent_key, &keyInfo2); |
| 485 | result = check_obj(&keyInfo, &keyInfo2); |
| 486 | if (result != TEE_SUCCESS) { |
| 487 | EMSG("keyInfo and keyInfo2 are different"); |
| 488 | goto cleanup2; |
| 489 | } |
| 490 | |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 491 | TEE_CloseObject(persistent_key); |
| 492 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 493 | result = TEE_OpenPersistentObject(params[0].value.a, |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 494 | &objectID, sizeof(objectID), |
| 495 | flags, &key); |
| 496 | if (result != TEE_SUCCESS) { |
| 497 | EMSG("Failed to open persistent key: 0x%x", result); |
| 498 | goto cleanup2; |
| 499 | } |
| 500 | |
| 501 | TEE_GetObjectInfo(key, &keyInfo3); |
| 502 | result = check_obj(&keyInfo3, &keyInfo2); |
| 503 | if (result != TEE_SUCCESS) { |
| 504 | EMSG("keyInfo2 and keyInfo3 are different"); |
| 505 | goto cleanup2; |
| 506 | } |
| 507 | |
| 508 | result = TEE_AllocateOperation(&encrypt_op, alg, TEE_MODE_ENCRYPT, |
| 509 | keyInfo3.maxObjectSize); |
| 510 | if (result != TEE_SUCCESS) { |
| 511 | EMSG("Failed to allocate an operation: 0x%x", result); |
| 512 | goto cleanup3; |
| 513 | } |
| 514 | |
| 515 | result = TEE_SetOperationKey(encrypt_op, key); |
| 516 | if (result != TEE_SUCCESS) { |
| 517 | EMSG("Failed to set operation key: 0x%x", result); |
| 518 | goto cleanup4; |
| 519 | } |
| 520 | |
| 521 | IV = TEE_Malloc(IVlen, 0); |
| 522 | if (!IV) { |
| 523 | EMSG("Out of memory for IV."); |
| 524 | result = TEE_ERROR_OUT_OF_MEMORY; |
| 525 | goto cleanup4; |
| 526 | } |
| 527 | |
| 528 | TEE_CipherInit(encrypt_op, IV, IVlen); |
| 529 | TEE_Free(IV); |
| 530 | |
| 531 | cleanup4: |
| 532 | TEE_FreeOperation(encrypt_op); |
| 533 | cleanup3: |
| 534 | TEE_CloseAndDeletePersistentObject1(key); |
| 535 | cleanup2: |
| 536 | TEE_FreeTransientObject(transient_key); |
| 537 | cleanup1: |
| 538 | return result; |
| 539 | } |
| 540 | |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 541 | TEE_Result ta_storage_cmd_loop(uint32_t param_types, TEE_Param params[4]) |
| 542 | { |
| 543 | TEE_ObjectHandle object = TEE_HANDLE_NULL; |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 544 | TEE_Result res = TEE_ERROR_GENERIC; |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 545 | int object_id = 0; |
| 546 | uint32_t flags = TEE_DATA_FLAG_OVERWRITE | |
| 547 | TEE_DATA_FLAG_ACCESS_WRITE_META; |
| 548 | int i = 0; |
| 549 | |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 550 | (void)params; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 551 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 552 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 553 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 554 | |
| 555 | for (i = 0; i < 20; i++) { |
| 556 | DMSG("\n\nLOOP : %d", i); |
| 557 | object = TEE_HANDLE_NULL; |
| 558 | object_id = i; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 559 | res = TEE_CreatePersistentObject(params[0].value.a, |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 560 | &object_id, sizeof(int), flags, |
| 561 | TEE_HANDLE_NULL, NULL, 0, |
| 562 | &object); |
| 563 | |
| 564 | if (res != TEE_SUCCESS) { |
| 565 | EMSG("FAIL"); |
| 566 | return res; |
| 567 | } |
| 568 | |
| 569 | res = TEE_CloseAndDeletePersistentObject1(object); |
| 570 | if (res != TEE_SUCCESS) { |
| 571 | EMSG("FAIL"); |
| 572 | return res; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return TEE_SUCCESS; |
| 577 | } |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 578 | |
| 579 | TEE_Result ta_storage_cmd_restrict_usage(uint32_t param_types, |
| 580 | TEE_Param params[4]) |
| 581 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 582 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 583 | |
| 584 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 585 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 586 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 587 | |
| 588 | o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a; |
| 589 | TEE_RestrictObjectUsage1(o, params[0].value.b); |
| 590 | return TEE_SUCCESS; |
| 591 | } |
| 592 | |
| 593 | TEE_Result ta_storage_cmd_alloc_obj(uint32_t param_types, TEE_Param params[4]) |
| 594 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 595 | TEE_Result res = TEE_ERROR_GENERIC; |
| 596 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 597 | |
| 598 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 599 | (TEE_PARAM_TYPE_VALUE_INPUT, |
| 600 | TEE_PARAM_TYPE_VALUE_OUTPUT, |
| 601 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 602 | |
| 603 | res = TEE_AllocateTransientObject(params[0].value.a, params[0].value.b, |
| 604 | &o); |
| 605 | params[1].value.a = (uint32_t)(uintptr_t)o; |
| 606 | return res; |
| 607 | } |
| 608 | |
| 609 | TEE_Result ta_storage_cmd_free_obj(uint32_t param_types, TEE_Param params[4]) |
| 610 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 611 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 612 | |
| 613 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 614 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 615 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 616 | |
| 617 | o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a; |
| 618 | TEE_FreeTransientObject(o); |
| 619 | return TEE_SUCCESS; |
| 620 | } |
| 621 | |
| 622 | TEE_Result ta_storage_cmd_reset_obj(uint32_t param_types, TEE_Param params[4]) |
| 623 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 624 | TEE_ObjectHandle o = TEE_HANDLE_NULL; |
Jens Wiklander | e6d4ddd | 2016-09-14 15:50:48 +0200 | [diff] [blame] | 625 | |
| 626 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 627 | (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, |
| 628 | TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)); |
| 629 | |
| 630 | o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a; |
| 631 | TEE_ResetTransientObject(o); |
| 632 | return TEE_SUCCESS; |
| 633 | } |
Guanchao Liang | 31a9cbf | 2016-12-20 00:35:26 +0800 | [diff] [blame] | 634 | |
| 635 | TEE_Result ta_storage_cmd_get_obj_info(uint32_t param_types, |
| 636 | TEE_Param params[4]) |
| 637 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 638 | TEE_Result res = TEE_ERROR_GENERIC; |
Jens Wiklander | fec6bea | 2023-03-29 14:14:18 +0200 | [diff] [blame^] | 639 | struct ta_storage_obj_info oi = { }; |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 640 | TEE_ObjectInfo info = { }; |
Guanchao Liang | 31a9cbf | 2016-12-20 00:35:26 +0800 | [diff] [blame] | 641 | TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a); |
| 642 | |
| 643 | ASSERT_PARAM_TYPE(TEE_PARAM_TYPES |
| 644 | (TEE_PARAM_TYPE_VALUE_INPUT, |
| 645 | TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE, |
| 646 | TEE_PARAM_TYPE_NONE)); |
| 647 | |
Jens Wiklander | fec6bea | 2023-03-29 14:14:18 +0200 | [diff] [blame^] | 648 | if (params[1].memref.size < sizeof(oi)) |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 649 | return TEE_ERROR_SHORT_BUFFER; |
| 650 | res = TEE_GetObjectInfo1(o, &info); |
| 651 | if (!res) { |
Jens Wiklander | fec6bea | 2023-03-29 14:14:18 +0200 | [diff] [blame^] | 652 | params[1].memref.size = sizeof(oi); |
| 653 | oi.object_type = info.objectType; |
| 654 | oi.object_size = info.objectSize; |
| 655 | oi.max_object_size = info.maxObjectSize; |
| 656 | oi.object_usage = info.objectUsage; |
| 657 | oi.data_size = info.dataSize; |
| 658 | oi.data_position = info.dataPosition; |
| 659 | oi.handle_flags = info.handleFlags; |
| 660 | TEE_MemMove(params[1].memref.buffer, &oi, sizeof(oi)); |
Jens Wiklander | c9d6c2f | 2020-09-11 10:13:54 +0200 | [diff] [blame] | 661 | } |
Guanchao Liang | 31a9cbf | 2016-12-20 00:35:26 +0800 | [diff] [blame] | 662 | |
| 663 | return res; |
| 664 | } |