Patrick Williams | 975a06f | 2022-10-21 14:42:47 -0500 | [diff] [blame^] | 1 | From ee767c1ae857cfcc8b4bb520b2558091e253cf94 Mon Sep 17 00:00:00 2001 |
| 2 | From: Satish Kumar <satish.kumar01@arm.com> |
| 3 | Date: Sun, 12 Dec 2021 10:57:17 +0000 |
| 4 | Subject: [PATCH 09/19] Use address instead of pointers |
| 5 | |
| 6 | Since secure enclave is 32bit and we 64bit there is an issue |
| 7 | in the protocol communication design that force us to handle |
| 8 | on our side the manipulation of address and pointers to make |
| 9 | this work. |
| 10 | |
| 11 | Upstream-Status: Pending |
| 12 | Signed-off-by: Satish Kumar <satish.kumar01@arm.com> |
| 13 | Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> |
| 14 | --- |
| 15 | .../service/common/include/psa/client.h | 15 ++++++++++++++ |
| 16 | .../service/common/psa_ipc/service_psa_ipc.c | 20 ++++++++++++------- |
| 17 | .../secure_storage_ipc/secure_storage_ipc.c | 20 +++++++++---------- |
| 18 | 3 files changed, 38 insertions(+), 17 deletions(-) |
| 19 | |
| 20 | diff --git a/components/service/common/include/psa/client.h b/components/service/common/include/psa/client.h |
| 21 | index 69ccf14f40a3..12dcd68f8a76 100644 |
| 22 | --- a/components/service/common/include/psa/client.h |
| 23 | +++ b/components/service/common/include/psa/client.h |
| 24 | @@ -81,6 +81,21 @@ struct __attribute__ ((__packed__)) psa_outvec { |
| 25 | uint32_t len; /*!< the size in bytes */ |
| 26 | }; |
| 27 | |
| 28 | +static void *psa_u32_to_ptr(uint32_t addr) |
| 29 | +{ |
| 30 | + return (void *)(uintptr_t)addr; |
| 31 | +} |
| 32 | + |
| 33 | +static uint32_t psa_ptr_to_u32(void *ptr) |
| 34 | +{ |
| 35 | + return (uintptr_t)ptr; |
| 36 | +} |
| 37 | + |
| 38 | +static uint32_t psa_ptr_const_to_u32(const void *ptr) |
| 39 | +{ |
| 40 | + return (uintptr_t)ptr; |
| 41 | +} |
| 42 | + |
| 43 | /*************************** PSA Client API **********************************/ |
| 44 | |
| 45 | /** |
| 46 | diff --git a/components/service/common/psa_ipc/service_psa_ipc.c b/components/service/common/psa_ipc/service_psa_ipc.c |
| 47 | index 5e5815dbc9cf..435c6c0a2eba 100644 |
| 48 | --- a/components/service/common/psa_ipc/service_psa_ipc.c |
| 49 | +++ b/components/service/common/psa_ipc/service_psa_ipc.c |
| 50 | @@ -62,6 +62,11 @@ static size_t psa_call_out_vec_len(const struct psa_outvec *out_vec, size_t out_ |
| 51 | return resp_len; |
| 52 | } |
| 53 | |
| 54 | +static uint32_t psa_virt_to_phys_u32(struct rpc_caller *caller, void *va) |
| 55 | +{ |
| 56 | + return (uintptr_t)rpc_caller_virt_to_phys(caller, va); |
| 57 | +} |
| 58 | + |
| 59 | psa_handle_t psa_connect(struct rpc_caller *caller, uint32_t sid, |
| 60 | uint32_t version) |
| 61 | { |
| 62 | @@ -147,20 +152,20 @@ psa_status_t psa_call(struct rpc_caller *caller, psa_handle_t psa_handle, |
| 63 | req_msg->params.psa_call_params.handle = psa_handle; |
| 64 | req_msg->params.psa_call_params.type = type; |
| 65 | req_msg->params.psa_call_params.in_len = in_len; |
| 66 | - req_msg->params.psa_call_params.in_vec = rpc_caller_virt_to_phys(caller, in_vec_param); |
| 67 | + req_msg->params.psa_call_params.in_vec = psa_virt_to_phys_u32(caller, in_vec_param); |
| 68 | req_msg->params.psa_call_params.out_len = out_len; |
| 69 | - req_msg->params.psa_call_params.out_vec = rpc_caller_virt_to_phys(caller, out_vec_param); |
| 70 | + req_msg->params.psa_call_params.out_vec = psa_virt_to_phys_u32(caller, out_vec_param); |
| 71 | |
| 72 | for (i = 0; i < in_len; i++) { |
| 73 | - in_vec_param[i].base = rpc_caller_virt_to_phys(caller, payload); |
| 74 | + in_vec_param[i].base = psa_virt_to_phys_u32(caller, payload); |
| 75 | in_vec_param[i].len = in_vec[i].len; |
| 76 | |
| 77 | - memcpy(payload, in_vec[i].base, in_vec[i].len); |
| 78 | + memcpy(payload, psa_u32_to_ptr(in_vec[i].base), in_vec[i].len); |
| 79 | payload += in_vec[i].len; |
| 80 | } |
| 81 | |
| 82 | for (i = 0; i < out_len; i++) { |
| 83 | - out_vec_param[i].base = NULL; |
| 84 | + out_vec_param[i].base = 0; |
| 85 | out_vec_param[i].len = out_vec[i].len; |
| 86 | } |
| 87 | |
| 88 | @@ -182,11 +187,12 @@ psa_status_t psa_call(struct rpc_caller *caller, psa_handle_t psa_handle, |
| 89 | goto caller_end; |
| 90 | |
| 91 | out_vec_param = (struct psa_outvec *)rpc_caller_phys_to_virt(caller, |
| 92 | - resp_msg->params.out_vec); |
| 93 | + psa_u32_to_ptr(resp_msg->params.out_vec)); |
| 94 | |
| 95 | for (i = 0; i < resp_msg->params.out_len; i++) { |
| 96 | out_vec[i].len = out_vec_param[i].len; |
| 97 | - memcpy(out_vec[i].base, rpc_caller_phys_to_virt(caller, out_vec_param[i].base), |
| 98 | + memcpy(psa_u32_to_ptr(out_vec[i].base), |
| 99 | + rpc_caller_phys_to_virt(caller, psa_u32_to_ptr(out_vec_param[i].base)), |
| 100 | out_vec[i].len); |
| 101 | } |
| 102 | |
| 103 | diff --git a/components/service/secure_storage/backend/secure_storage_ipc/secure_storage_ipc.c b/components/service/secure_storage/backend/secure_storage_ipc/secure_storage_ipc.c |
| 104 | index a1f369db253e..bda442a61d5c 100644 |
| 105 | --- a/components/service/secure_storage/backend/secure_storage_ipc/secure_storage_ipc.c |
| 106 | +++ b/components/service/secure_storage/backend/secure_storage_ipc/secure_storage_ipc.c |
| 107 | @@ -22,9 +22,9 @@ static psa_status_t secure_storage_ipc_set(void *context, uint32_t client_id, |
| 108 | psa_handle_t psa_handle; |
| 109 | psa_status_t psa_status; |
| 110 | struct psa_invec in_vec[] = { |
| 111 | - { .base = &uid, .len = sizeof(uid) }, |
| 112 | - { .base = p_data, .len = data_length }, |
| 113 | - { .base = &create_flags, .len = sizeof(create_flags) }, |
| 114 | + { .base = psa_ptr_to_u32(&uid), .len = sizeof(uid) }, |
| 115 | + { .base = psa_ptr_const_to_u32(p_data), .len = data_length }, |
| 116 | + { .base = psa_ptr_to_u32(&create_flags), .len = sizeof(create_flags) }, |
| 117 | }; |
| 118 | |
| 119 | (void)client_id; |
| 120 | @@ -53,11 +53,11 @@ static psa_status_t secure_storage_ipc_get(void *context, |
| 121 | psa_status_t psa_status; |
| 122 | uint32_t offset = (uint32_t)data_offset; |
| 123 | struct psa_invec in_vec[] = { |
| 124 | - { .base = &uid, .len = sizeof(uid) }, |
| 125 | - { .base = &offset, .len = sizeof(offset) }, |
| 126 | + { .base = psa_ptr_to_u32(&uid), .len = sizeof(uid) }, |
| 127 | + { .base = psa_ptr_to_u32(&offset), .len = sizeof(offset) }, |
| 128 | }; |
| 129 | struct psa_outvec out_vec[] = { |
| 130 | - { .base = p_data, .len = data_size }, |
| 131 | + { .base = psa_ptr_to_u32(p_data), .len = data_size }, |
| 132 | }; |
| 133 | |
| 134 | if (!p_data_length) { |
| 135 | @@ -84,10 +84,10 @@ static psa_status_t secure_storage_ipc_get_info(void *context, |
| 136 | psa_handle_t psa_handle; |
| 137 | psa_status_t psa_status; |
| 138 | struct psa_invec in_vec[] = { |
| 139 | - { .base = &uid, .len = sizeof(uid) }, |
| 140 | + { .base = psa_ptr_to_u32(&uid), .len = sizeof(uid) }, |
| 141 | }; |
| 142 | struct psa_outvec out_vec[] = { |
| 143 | - { .base = p_info, .len = sizeof(*p_info) }, |
| 144 | + { .base = psa_ptr_to_u32(p_info), .len = sizeof(*p_info) }, |
| 145 | }; |
| 146 | |
| 147 | (void)client_id; |
| 148 | @@ -110,7 +110,7 @@ static psa_status_t secure_storage_ipc_remove(void *context, |
| 149 | psa_handle_t psa_handle; |
| 150 | psa_status_t psa_status; |
| 151 | struct psa_invec in_vec[] = { |
| 152 | - { .base = &uid, .len = sizeof(uid) }, |
| 153 | + { .base = psa_ptr_to_u32(&uid), .len = sizeof(uid) }, |
| 154 | }; |
| 155 | |
| 156 | (void)client_id; |
| 157 | @@ -164,7 +164,7 @@ static uint32_t secure_storage_get_support(void *context, uint32_t client_id) |
| 158 | psa_status_t psa_status; |
| 159 | uint32_t support_flags; |
| 160 | struct psa_outvec out_vec[] = { |
| 161 | - { .base = &support_flags, .len = sizeof(support_flags) }, |
| 162 | + { .base = psa_ptr_to_u32(&support_flags), .len = sizeof(support_flags) }, |
| 163 | }; |
| 164 | |
| 165 | (void)client_id; |
| 166 | -- |
| 167 | 2.38.0 |
| 168 | |