diff options
author | Jens Wiklander <jens.wiklander@linaro.org> | 2020-06-21 22:08:32 +0200 |
---|---|---|
committer | Jérôme Forissier <jerome@forissier.org> | 2020-09-24 15:39:13 +0200 |
commit | c40a65057606debb80f0d467c956561a3cb550e9 (patch) | |
tree | 38496a261c4b98192f19bc89e633762553be6208 /core/tee | |
parent | fe80fd793488c3f86389927555ae5132f1af4269 (diff) |
core: separate copy_from_user() and friends
Removes the tee_svc_ prefix and moves tee_svc_copy_from_user() and
friends into <kernel/user_access.h> and core/kernel/user/access.c
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'core/tee')
-rw-r--r-- | core/tee/tee_svc.c | 122 | ||||
-rw-r--r-- | core/tee/tee_svc_cryp.c | 90 | ||||
-rw-r--r-- | core/tee/tee_svc_storage.c | 38 |
3 files changed, 99 insertions, 151 deletions
diff --git a/core/tee/tee_svc.c b/core/tee/tee_svc.c index 78b6a23f..3b7b5acc 100644 --- a/core/tee/tee_svc.c +++ b/core/tee/tee_svc.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2014, STMicroelectronics International N.V. + * Copyright (c) 2020, Linaro Limited */ + #include <kernel/chip_services.h> #include <kernel/pseudo_ta.h> #include <kernel/tee_common.h> @@ -9,6 +11,7 @@ #include <kernel/tee_ta_manager.h> #include <kernel/tee_time.h> #include <kernel/trace_ta.h> +#include <kernel/user_access.h> #include <mm/core_memprot.h> #include <mm/mobj.h> #include <mm/tee_mm.h> @@ -36,7 +39,7 @@ void syscall_log(const void *buf __maybe_unused, size_t len __maybe_unused) if (kbuf == NULL) return; - if (tee_svc_copy_from_user(kbuf, buf, len) == TEE_SUCCESS) { + if (copy_from_user(kbuf, buf, len) == TEE_SUCCESS) { kbuf[len] = '\0'; trace_ext_puts(kbuf); } @@ -144,7 +147,7 @@ static TEE_Result get_prop_tee_dev_id(struct tee_ta_session *sess __unused, uuid.clockSeqAndNode[0] &= 0x3f; uuid.clockSeqAndNode[0] |= 0x80; - return tee_svc_copy_to_user(buf, &uuid, sizeof(TEE_UUID)); + return copy_to_user(buf, &uuid, sizeof(TEE_UUID)); } static TEE_Result get_prop_tee_sys_time_prot_level( @@ -159,7 +162,7 @@ static TEE_Result get_prop_tee_sys_time_prot_level( } *blen = sizeof(prot); prot = tee_time_get_sys_time_protection_level(); - return tee_svc_copy_to_user(buf, &prot, sizeof(prot)); + return copy_to_user(buf, &prot, sizeof(prot)); } static TEE_Result get_prop_client_id(struct tee_ta_session *sess __unused, @@ -170,7 +173,7 @@ static TEE_Result get_prop_client_id(struct tee_ta_session *sess __unused, return TEE_ERROR_SHORT_BUFFER; } *blen = sizeof(TEE_Identity); - return tee_svc_copy_to_user(buf, &sess->clnt_id, sizeof(TEE_Identity)); + return copy_to_user(buf, &sess->clnt_id, sizeof(TEE_Identity)); } static TEE_Result get_prop_ta_app_id(struct tee_ta_session *sess, @@ -181,7 +184,7 @@ static TEE_Result get_prop_ta_app_id(struct tee_ta_session *sess, return TEE_ERROR_SHORT_BUFFER; } *blen = sizeof(TEE_UUID); - return tee_svc_copy_to_user(buf, &sess->ctx->uuid, sizeof(TEE_UUID)); + return copy_to_user(buf, &sess->ctx->uuid, sizeof(TEE_UUID)); } /* Properties of the set TEE_PROPSET_CURRENT_CLIENT */ @@ -383,15 +386,15 @@ TEE_Result syscall_get_property(unsigned long prop_set, /* Get the property type */ if (prop_type) { - res = tee_svc_copy_to_user(prop_type, &prop->prop_type, - sizeof(*prop_type)); + res = copy_to_user(prop_type, &prop->prop_type, + sizeof(*prop_type)); if (res != TEE_SUCCESS) return res; } /* Get the property */ if (buf && blen) { - res = tee_svc_copy_from_user(&klen, blen, sizeof(klen)); + res = copy_from_user(&klen, blen, sizeof(klen)); if (res != TEE_SUCCESS) return res; @@ -399,15 +402,13 @@ TEE_Result syscall_get_property(unsigned long prop_set, klen_size = klen; res = prop->get_prop_func(sess, buf, &klen_size); klen = klen_size; - res2 = tee_svc_copy_to_user(blen, &klen, sizeof(*blen)); + res2 = copy_to_user(blen, &klen, sizeof(*blen)); } else { if (klen < prop->len) res = TEE_ERROR_SHORT_BUFFER; else - res = tee_svc_copy_to_user(buf, prop->data, - prop->len); - res2 = tee_svc_copy_to_user(blen, &prop->len, - sizeof(*blen)); + res = copy_to_user(buf, prop->data, prop->len); + res2 = copy_to_user(blen, &prop->len, sizeof(*blen)); } if (res2 != TEE_SUCCESS) return res2; @@ -417,7 +418,7 @@ TEE_Result syscall_get_property(unsigned long prop_set, /* Get the property name */ if (name && name_len) { - res = tee_svc_copy_from_user(&klen, name_len, sizeof(klen)); + res = copy_from_user(&klen, name_len, sizeof(klen)); if (res != TEE_SUCCESS) return res; @@ -426,8 +427,8 @@ TEE_Result syscall_get_property(unsigned long prop_set, if (klen < elen) res = TEE_ERROR_SHORT_BUFFER; else - res = tee_svc_copy_to_user(name, prop->name, elen); - res2 = tee_svc_copy_to_user(name_len, &elen, sizeof(*name_len)); + res = copy_to_user(name, prop->name, elen); + res2 = copy_to_user(name_len, &elen, sizeof(*name_len)); if (res2 != TEE_SUCCESS) return res2; if (res != TEE_SUCCESS) @@ -470,7 +471,7 @@ TEE_Result syscall_get_property_name_to_index(unsigned long prop_set, kname = malloc(name_len); if (!kname) return TEE_ERROR_OUT_OF_MEMORY; - res = tee_svc_copy_from_user(kname, name, name_len); + res = copy_from_user(kname, name, name_len); if (res != TEE_SUCCESS) goto out; kname[name_len - 1] = 0; @@ -478,13 +479,13 @@ TEE_Result syscall_get_property_name_to_index(unsigned long prop_set, res = TEE_ERROR_ITEM_NOT_FOUND; for (i = 0; i < size; i++) { if (!strcmp(kname, props[i].name)) { - res = tee_svc_copy_to_user(index, &i, sizeof(*index)); + res = copy_to_user(index, &i, sizeof(*index)); goto out; } } for (i = size; i < size + vendor_size; i++) { if (!strcmp(kname, vendor_props[i - size].name)) { - res = tee_svc_copy_to_user(index, &i, sizeof(*index)); + res = copy_to_user(index, &i, sizeof(*index)); goto out; } } @@ -670,8 +671,8 @@ static TEE_Result tee_svc_copy_param(struct tee_ta_session *sess, case TEE_PARAM_TYPE_MEMREF_INOUT: va = (void *)param->u[n].mem.offs; if (va) { - res = tee_svc_copy_from_user(dst, va, - param->u[n].mem.size); + res = copy_from_user(dst, va, + param->u[n].mem.size); if (res != TEE_SUCCESS) return res; param->u[n].mem.offs = dst_offs; @@ -717,6 +718,7 @@ static TEE_Result tee_svc_update_out_param( { size_t n; uint64_t *vals = usr_param->vals; + size_t sz = 0; for (n = 0; n < TEE_NUM_PARAMS; n++) { switch (TEE_PARAM_TYPE_GET(param->types, n)) { @@ -728,11 +730,11 @@ static TEE_Result tee_svc_update_out_param( * a temporary buffer is used. Otherwise only the * size needs to be updated. */ - if (tmp_buf_va[n] && - param->u[n].mem.size <= vals[n * 2 + 1]) { + sz = param->u[n].mem.size; + if (tmp_buf_va[n] && sz <= vals[n * 2 + 1]) { void *src = tmp_buf_va[n]; void *dst = (void *)(uintptr_t)vals[n * 2]; - TEE_Result res; + TEE_Result res = TEE_SUCCESS; /* * TA is allowed to return a size larger than @@ -740,14 +742,13 @@ static TEE_Result tee_svc_update_out_param( * data should be synchronized as per TEE Client * API spec. */ - if (param->u[n].mem.size <= tmp_buf_size[n]) { - res = tee_svc_copy_to_user(dst, src, - param->u[n].mem.size); + if (sz <= tmp_buf_size[n]) { + res = copy_to_user(dst, src, sz); if (res != TEE_SUCCESS) return res; } } - usr_param->vals[n * 2 + 1] = param->u[n].mem.size; + usr_param->vals[n * 2 + 1] = sz; break; case TEE_PARAM_TYPE_VALUE_OUTPUT: @@ -794,7 +795,7 @@ TEE_Result syscall_open_ta_session(const TEE_UUID *dest, goto out_free_only; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_copy_from_user(uuid, dest, sizeof(TEE_UUID)); + res = copy_from_user(uuid, dest, sizeof(TEE_UUID)); if (res != TEE_SUCCESS) goto function_exit; @@ -818,8 +819,8 @@ TEE_Result syscall_open_ta_session(const TEE_UUID *dest, function_exit: mobj_put_wipe(mobj_param); if (res == TEE_SUCCESS) - tee_svc_copy_to_user(ta_sess, &s->id, sizeof(s->id)); - tee_svc_copy_to_user(ret_orig, &ret_o, sizeof(ret_o)); + copy_to_user(ta_sess, &s->id, sizeof(s->id)); + copy_to_user(ret_orig, &ret_o, sizeof(ret_o)); out_free_only: free_wipe(param); @@ -909,7 +910,7 @@ function_exit: tee_ta_put_session(called_sess); mobj_put_wipe(mobj_param); if (ret_orig) - tee_svc_copy_to_user(ret_orig, &ret_o, sizeof(ret_o)); + copy_to_user(ret_orig, &ret_o, sizeof(ret_o)); return res; } @@ -927,53 +928,6 @@ TEE_Result syscall_check_access_rights(unsigned long flags, const void *buf, (uaddr_t)buf, len); } -TEE_Result tee_svc_copy_from_user(void *kaddr, const void *uaddr, size_t len) -{ - struct tee_ta_session *s = NULL; - TEE_Result res = TEE_SUCCESS; - - res = tee_ta_get_current_session(&s); - if (res != TEE_SUCCESS) - return res; - - res = tee_mmu_check_access_rights(&to_user_ta_ctx(s->ctx)->uctx, - TEE_MEMORY_ACCESS_READ | - TEE_MEMORY_ACCESS_ANY_OWNER, - (uaddr_t)uaddr, len); - if (res != TEE_SUCCESS) - return res; - - memcpy(kaddr, uaddr, len); - return TEE_SUCCESS; -} - -TEE_Result tee_svc_copy_to_user(void *uaddr, const void *kaddr, size_t len) -{ - struct tee_ta_session *s = NULL; - TEE_Result res = TEE_SUCCESS; - - res = tee_ta_get_current_session(&s); - if (res != TEE_SUCCESS) - return res; - - res = tee_mmu_check_access_rights(&to_user_ta_ctx(s->ctx)->uctx, - TEE_MEMORY_ACCESS_WRITE | - TEE_MEMORY_ACCESS_ANY_OWNER, - (uaddr_t)uaddr, len); - if (res != TEE_SUCCESS) - return res; - - memcpy(uaddr, kaddr, len); - return TEE_SUCCESS; -} - -TEE_Result tee_svc_copy_kaddr_to_uref(uint32_t *uref, void *kaddr) -{ - uint32_t ref = tee_svc_kaddr_to_uref(kaddr); - - return tee_svc_copy_to_user(uref, &ref, sizeof(ref)); -} - TEE_Result syscall_get_cancellation_flag(uint32_t *cancel) { TEE_Result res; @@ -986,7 +940,7 @@ TEE_Result syscall_get_cancellation_flag(uint32_t *cancel) c = tee_ta_session_is_cancelled(s, NULL); - return tee_svc_copy_to_user(cancel, &c, sizeof(c)); + return copy_to_user(cancel, &c, sizeof(c)); } TEE_Result syscall_unmask_cancellation(uint32_t *old_mask) @@ -1001,7 +955,7 @@ TEE_Result syscall_unmask_cancellation(uint32_t *old_mask) m = s->cancel_mask; s->cancel_mask = false; - return tee_svc_copy_to_user(old_mask, &m, sizeof(m)); + return copy_to_user(old_mask, &m, sizeof(m)); } TEE_Result syscall_mask_cancellation(uint32_t *old_mask) @@ -1016,7 +970,7 @@ TEE_Result syscall_mask_cancellation(uint32_t *old_mask) m = s->cancel_mask; s->cancel_mask = true; - return tee_svc_copy_to_user(old_mask, &m, sizeof(m)); + return copy_to_user(old_mask, &m, sizeof(m)); } TEE_Result syscall_wait(unsigned long timeout) @@ -1080,7 +1034,7 @@ TEE_Result syscall_get_time(unsigned long cat, TEE_Time *mytime) } if (res == TEE_SUCCESS || res == TEE_ERROR_OVERFLOW) { - res2 = tee_svc_copy_to_user(mytime, &t, sizeof(t)); + res2 = copy_to_user(mytime, &t, sizeof(t)); if (res2 != TEE_SUCCESS) res = res2; } @@ -1098,7 +1052,7 @@ TEE_Result syscall_set_ta_time(const TEE_Time *mytime) if (res != TEE_SUCCESS) return res; - res = tee_svc_copy_from_user(&t, mytime, sizeof(t)); + res = copy_from_user(&t, mytime, sizeof(t)); if (res != TEE_SUCCESS) return res; diff --git a/core/tee/tee_svc_cryp.c b/core/tee/tee_svc_cryp.c index c1f1ceb3..060222e2 100644 --- a/core/tee/tee_svc_cryp.c +++ b/core/tee/tee_svc_cryp.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2014, STMicroelectronics International N.V. + * Copyright (c) 2020, Linaro Limited */ #include <assert.h> @@ -8,11 +9,13 @@ #include <config.h> #include <crypto/crypto.h> #include <kernel/tee_ta_manager.h> +#include <kernel/user_access.h> #include <mm/tee_mmu.h> #include <stdlib_ext.h> #include <string_ext.h> #include <string.h> #include <sys/queue.h> +#include <tee_api_defines_extensions.h> #include <tee_api_types.h> #include <tee/tee_cryp_utl.h> #include <tee/tee_obj.h> @@ -21,7 +24,6 @@ #include <trace.h> #include <utee_defines.h> #include <util.h> -#include <tee_api_defines_extensions.h> #if defined(CFG_CRYPTO_HKDF) #include <tee/tee_cryp_hkdf.h> #endif @@ -580,19 +582,19 @@ static TEE_Result op_attr_secret_value_to_user(void *attr, uint64_t s; uint64_t key_size; - res = tee_svc_copy_from_user(&s, size, sizeof(s)); + res = copy_from_user(&s, size, sizeof(s)); if (res != TEE_SUCCESS) return res; key_size = key->key_size; - res = tee_svc_copy_to_user(size, &key_size, sizeof(key_size)); + res = copy_to_user(size, &key_size, sizeof(key_size)); if (res != TEE_SUCCESS) return res; if (s < key->key_size || !buffer) return TEE_ERROR_SHORT_BUFFER; - return tee_svc_copy_to_user(buffer, key + 1, key->key_size); + return copy_to_user(buffer, key + 1, key->key_size); } static TEE_Result op_attr_secret_value_to_binary(void *attr, void *data, @@ -675,12 +677,12 @@ static TEE_Result op_attr_bignum_to_user(void *attr, uint64_t req_size = 0; uint64_t s = 0; - res = tee_svc_copy_from_user(&s, size, sizeof(s)); + res = copy_from_user(&s, size, sizeof(s)); if (res != TEE_SUCCESS) return res; req_size = crypto_bignum_num_bytes(*bn); - res = tee_svc_copy_to_user(size, &req_size, sizeof(req_size)); + res = copy_to_user(size, &req_size, sizeof(req_size)); if (res != TEE_SUCCESS) return res; if (!req_size) @@ -790,14 +792,14 @@ static TEE_Result op_attr_value_to_user(void *attr, uint32_t value[2] = { *v }; uint64_t req_size = sizeof(value); - res = tee_svc_copy_from_user(&s, size, sizeof(s)); + res = copy_from_user(&s, size, sizeof(s)); if (res != TEE_SUCCESS) return res; if (s < req_size || !buffer) return TEE_ERROR_SHORT_BUFFER; - return tee_svc_copy_to_user(buffer, value, req_size); + return copy_to_user(buffer, value, req_size); } static TEE_Result op_attr_value_to_binary(void *attr, void *data, @@ -865,7 +867,7 @@ static const struct attr_ops attr_ops[] = { static TEE_Result get_user_u64_as_size_t(size_t *dst, uint64_t *src) { uint64_t d = 0; - TEE_Result res = tee_svc_copy_from_user(&d, src, sizeof(d)); + TEE_Result res = copy_from_user(&d, src, sizeof(d)); /* * On 32-bit systems a size_t can't hold a uint64_t so we need to @@ -881,7 +883,7 @@ static TEE_Result put_user_u64(uint64_t *dst, size_t value) { uint64_t v = value; - return tee_svc_copy_to_user(dst, &v, sizeof(v)); + return copy_to_user(dst, &v, sizeof(v)); } TEE_Result syscall_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info) @@ -895,11 +897,11 @@ TEE_Result syscall_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info) goto exit; res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) goto exit; - res = tee_svc_copy_to_user(info, &o->info, sizeof(o->info)); + res = copy_to_user(info, &o->info, sizeof(o->info)); exit: return res; @@ -916,8 +918,7 @@ TEE_Result syscall_cryp_obj_restrict_usage(unsigned long obj, if (res != TEE_SUCCESS) goto exit; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) goto exit; @@ -992,8 +993,7 @@ TEE_Result syscall_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id, if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return TEE_ERROR_ITEM_NOT_FOUND; @@ -1318,7 +1318,7 @@ TEE_Result syscall_cryp_obj_alloc(unsigned long obj_type, tee_obj_add(to_user_ta_ctx(sess->ctx), o); - res = tee_svc_copy_kaddr_to_uref(obj, o); + res = copy_kaddr_to_uref(obj, o); if (res != TEE_SUCCESS) tee_obj_close(to_user_ta_ctx(sess->ctx), o); return res; @@ -1334,8 +1334,7 @@ TEE_Result syscall_cryp_obj_close(unsigned long obj) if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -1360,8 +1359,7 @@ TEE_Result syscall_cryp_obj_reset(unsigned long obj) if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -1614,8 +1612,7 @@ TEE_Result syscall_cryp_obj_populate(unsigned long obj, if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -1671,12 +1668,12 @@ TEE_Result syscall_cryp_obj_copy(unsigned long dst, unsigned long src) return res; res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(dst), &dst_o); + uref_to_vaddr(dst), &dst_o); if (res != TEE_SUCCESS) return res; res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(src), &src_o); + uref_to_vaddr(src), &src_o); if (res != TEE_SUCCESS) return res; @@ -1820,8 +1817,7 @@ TEE_Result syscall_obj_generate_key(unsigned long obj, unsigned long key_size, if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -2119,7 +2115,7 @@ TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long mode, utc = to_user_ta_ctx(sess->ctx); if (key1 != 0) { - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(key1), &o1); + res = tee_obj_get(utc, uref_to_vaddr(key1), &o1); if (res != TEE_SUCCESS) return res; if (o1->busy) @@ -2129,7 +2125,7 @@ TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long mode, return res; } if (key2 != 0) { - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(key2), &o2); + res = tee_obj_get(utc, uref_to_vaddr(key2), &o2); if (res != TEE_SUCCESS) return res; if (o2->busy) @@ -2211,7 +2207,7 @@ TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long mode, if (res != TEE_SUCCESS) goto out; - res = tee_svc_copy_kaddr_to_uref(state, cs); + res = copy_kaddr_to_uref(state, cs); if (res != TEE_SUCCESS) goto out; @@ -2242,11 +2238,11 @@ TEE_Result syscall_cryp_state_copy(unsigned long dst, unsigned long src) if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(dst), &cs_dst); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(dst), &cs_dst); if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(src), &cs_src); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(src), &cs_src); if (res != TEE_SUCCESS) return res; if (cs_dst->algo != cs_src->algo || cs_dst->mode != cs_src->mode) @@ -2292,7 +2288,7 @@ TEE_Result syscall_cryp_state_free(unsigned long state) if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; cryp_state_free(to_user_ta_ctx(sess->ctx), cs); @@ -2311,7 +2307,7 @@ TEE_Result syscall_hash_init(unsigned long state, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2376,7 +2372,7 @@ TEE_Result syscall_hash_update(unsigned long state, const void *chunk, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2438,7 +2434,7 @@ TEE_Result syscall_hash_final(unsigned long state, const void *chunk, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2511,7 +2507,7 @@ TEE_Result syscall_cipher_init(unsigned long state, const void *iv, return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2570,7 +2566,7 @@ static TEE_Result tee_svc_cipher_update_helper(unsigned long state, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2906,7 +2902,7 @@ TEE_Result syscall_cryp_derive_key(unsigned long state, return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -2927,7 +2923,7 @@ TEE_Result syscall_cryp_derive_key(unsigned long state, if (res != TEE_SUCCESS) goto out; - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(derived_key), &so); + res = tee_obj_get(utc, uref_to_vaddr(derived_key), &so); if (res != TEE_SUCCESS) goto out; @@ -3214,7 +3210,7 @@ TEE_Result syscall_authenc_init(unsigned long state, const void *nonce, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3256,7 +3252,7 @@ TEE_Result syscall_authenc_update_aad(unsigned long state, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3288,7 +3284,7 @@ TEE_Result syscall_authenc_update_payload(unsigned long state, if (res != TEE_SUCCESS) return res; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3353,7 +3349,7 @@ TEE_Result syscall_authenc_enc_final(unsigned long state, const void *src_data, uctx = &to_user_ta_ctx(sess->ctx)->uctx; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3443,7 +3439,7 @@ TEE_Result syscall_authenc_dec_final(unsigned long state, uctx = &to_user_ta_ctx(sess->ctx)->uctx; - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3549,7 +3545,7 @@ TEE_Result syscall_asymm_operate(unsigned long state, return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; @@ -3734,7 +3730,7 @@ TEE_Result syscall_asymm_verify(unsigned long state, return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_cryp_get_state(sess, tee_svc_uref_to_vaddr(state), &cs); + res = tee_svc_cryp_get_state(sess, uref_to_vaddr(state), &cs); if (res != TEE_SUCCESS) return res; diff --git a/core/tee/tee_svc_storage.c b/core/tee/tee_svc_storage.c index 167d6938..bdac25f7 100644 --- a/core/tee/tee_svc_storage.c +++ b/core/tee/tee_svc_storage.c @@ -1,11 +1,13 @@ // SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2014, STMicroelectronics International N.V. + * Copyright (c) 2020, Linaro Limited */ #include <kernel/mutex.h> #include <kernel/tee_misc.h> #include <kernel/tee_ta_manager.h> +#include <kernel/user_access.h> #include <mm/tee_mmu.h> #include <string.h> #include <tee_api_defines_extensions.h> @@ -322,7 +324,7 @@ TEE_Result syscall_storage_obj_open(unsigned long storage_id, void *object_id, goto oclose; } - res = tee_svc_copy_kaddr_to_uref(obj, o); + res = copy_kaddr_to_uref(obj, o); if (res != TEE_SUCCESS) goto oclose; @@ -475,8 +477,7 @@ TEE_Result syscall_storage_obj_create(unsigned long storage_id, void *object_id, o->pobj = po; if (attr != TEE_HANDLE_NULL) { - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(attr), - &attr_o); + res = tee_obj_get(utc, uref_to_vaddr(attr), &attr_o); if (res != TEE_SUCCESS) goto err; /* The supplied handle must be one of an initialized object */ @@ -494,7 +495,7 @@ TEE_Result syscall_storage_obj_create(unsigned long storage_id, void *object_id, po = NULL; /* o owns it from now on */ tee_obj_add(utc, o); - res = tee_svc_copy_kaddr_to_uref(obj, o); + res = copy_kaddr_to_uref(obj, o); if (res != TEE_SUCCESS) goto oclose; @@ -532,7 +533,7 @@ TEE_Result syscall_storage_obj_del(unsigned long obj) return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(utc, uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -568,7 +569,7 @@ TEE_Result syscall_storage_obj_rename(unsigned long obj, void *object_id, return res; utc = to_user_ta_ctx(sess->ctx); - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(utc, uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; @@ -639,7 +640,7 @@ TEE_Result syscall_storage_alloc_enum(uint32_t *obj_enum) e->fops = NULL; TAILQ_INSERT_TAIL(&utc->storage_enums, e, link); - return tee_svc_copy_kaddr_to_uref(obj_enum, e); + return copy_kaddr_to_uref(obj_enum, e); } TEE_Result syscall_storage_free_enum(unsigned long obj_enum) @@ -655,7 +656,7 @@ TEE_Result syscall_storage_free_enum(unsigned long obj_enum) utc = to_user_ta_ctx(sess->ctx); res = tee_svc_storage_get_enum(utc, - tee_svc_uref_to_vaddr(obj_enum), &e); + uref_to_vaddr(obj_enum), &e); if (res != TEE_SUCCESS) return res; @@ -673,7 +674,7 @@ TEE_Result syscall_storage_reset_enum(unsigned long obj_enum) return res; res = tee_svc_storage_get_enum(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj_enum), &e); + uref_to_vaddr(obj_enum), &e); if (res != TEE_SUCCESS) return res; @@ -701,7 +702,7 @@ TEE_Result syscall_storage_start_enum(unsigned long obj_enum, return res; res = tee_svc_storage_get_enum(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj_enum), &e); + uref_to_vaddr(obj_enum), &e); if (res != TEE_SUCCESS) return res; @@ -734,8 +735,7 @@ TEE_Result syscall_storage_next_enum(unsigned long obj_enum, goto exit; utc = to_user_ta_ctx(sess->ctx); - res = tee_svc_storage_get_enum(utc, - tee_svc_uref_to_vaddr(obj_enum), &e); + res = tee_svc_storage_get_enum(utc, uref_to_vaddr(obj_enum), &e); if (res != TEE_SUCCESS) goto exit; @@ -787,7 +787,7 @@ TEE_Result syscall_storage_next_enum(unsigned long obj_enum, memcpy(obj_id, o->pobj->obj_id, o->pobj->obj_id_len); l = o->pobj->obj_id_len; - res = tee_svc_copy_to_user(len, &l, sizeof(*len)); + res = copy_to_user(len, &l, sizeof(*len)); exit: if (o) { @@ -814,7 +814,7 @@ TEE_Result syscall_storage_obj_read(unsigned long obj, void *data, size_t len, goto exit; utc = to_user_ta_ctx(sess->ctx); - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(utc, uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) goto exit; @@ -859,7 +859,7 @@ TEE_Result syscall_storage_obj_read(unsigned long obj, void *data, size_t len, o->info.dataPosition += bytes; u_count = bytes; - res = tee_svc_copy_to_user(count, &u_count, sizeof(*count)); + res = copy_to_user(count, &u_count, sizeof(*count)); exit: return res; } @@ -877,7 +877,7 @@ TEE_Result syscall_storage_obj_write(unsigned long obj, void *data, size_t len) goto exit; utc = to_user_ta_ctx(sess->ctx); - res = tee_obj_get(utc, tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(utc, uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) goto exit; @@ -933,8 +933,7 @@ TEE_Result syscall_storage_obj_trunc(unsigned long obj, size_t len) if (res != TEE_SUCCESS) goto exit; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) goto exit; @@ -991,8 +990,7 @@ TEE_Result syscall_storage_obj_seek(unsigned long obj, int32_t offset, if (res != TEE_SUCCESS) return res; - res = tee_obj_get(to_user_ta_ctx(sess->ctx), - tee_svc_uref_to_vaddr(obj), &o); + res = tee_obj_get(to_user_ta_ctx(sess->ctx), uref_to_vaddr(obj), &o); if (res != TEE_SUCCESS) return res; |