Skip to content

Commit 134a169

Browse files
author
Michael Schwarcz
committed
TF-M patch: Handle extended stack frame in tfm_svcall_psa_call
- Fix failing attestation test on LPC55S69 - Link to bug tracking: https://developer.trustedfirmware.org/T276
1 parent 5c79394 commit 134a169

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_svcalls.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller);
5858
* handle, in_vec, in_len, out_vec, out_len.
5959
* \param[in] ns_caller If 'non-zero', call from non-secure client.
6060
* Or from secure client.
61+
* \param[in] lr Link register to be stored
6162
*
6263
* \retval >=0 RoT Service-specific status value.
6364
* \retval <0 RoT Service-specific error code.
@@ -73,7 +74,7 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller);
7374
* \arg The message is unrecognized by the RoT
7475
* Service or incorrectly formatted.
7576
*/
76-
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller);
77+
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr);
7778

7879
/**
7980
* \brief SVC handler for \ref psa_close.
@@ -96,10 +97,11 @@ void tfm_svcall_psa_close(uint32_t *args, int32_t ns_caller);
9697
*
9798
* \param[in] svc_num SVC number
9899
* \param[in] ctx Argument context
100+
* \param[in] lr Link register to be stored
99101
*
100102
* \returns Return values from those who has,
101103
* or PSA_SUCCESS.
102104
*/
103-
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx);
105+
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr);
104106

105107
#endif

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_svcalls.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller)
107107
return PSA_NULL_HANDLE;
108108
}
109109

110-
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller)
110+
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr)
111111
{
112112
psa_handle_t handle;
113113
psa_invec *inptr, invecs[PSA_MAX_IOVEC];
@@ -124,14 +124,17 @@ psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller)
124124
in_num = (size_t)args[2];
125125
outptr = (psa_outvec *)args[3];
126126
/*
127-
* FixMe: 5th parameter is pushed at stack top before SVC; plus
128-
* exception stacked contents, 5th parameter is now at 8th position
129-
* in SVC handler. However, if thread mode applies FloatPoint, then
130-
* FloatPoint context is pushed into stack and then 5th parameter
131-
* will not be args[8].
132-
* Will refine it later.
127+
* 5th parameter is pushed at stack top before SVC; plus exception stacked contents,
128+
* 5th parameter is now at 8th position in SVC handler.
129+
* However, if thread mode applies FloatPoint, then FloatPoint context is pushed into
130+
* stack and then 5th parameter will be args[26].
133131
*/
134-
out_num = (size_t)args[8];
132+
if (lr & EXC_RETURN_FPU_FRAME_BASIC) {
133+
out_num = (size_t)args[8];
134+
}
135+
else {
136+
out_num = (size_t)args[26];
137+
}
135138
} else {
136139
/*
137140
* FixMe: From non-secure caller, vec and len are composed into a new
@@ -926,7 +929,7 @@ static void tfm_svcall_psa_eoi(uint32_t *args)
926929
/* FixMe: re-enable interrupt */
927930
}
928931

929-
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx)
932+
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr)
930933
{
931934
switch (svc_num) {
932935
case TFM_SVC_SCHEDULE:
@@ -939,7 +942,7 @@ int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx)
939942
case TFM_SVC_PSA_CONNECT:
940943
return tfm_svcall_psa_connect(ctx, 0);
941944
case TFM_SVC_PSA_CALL:
942-
return tfm_svcall_psa_call(ctx, 0);
945+
return tfm_svcall_psa_call(ctx, 0, lr);
943946
case TFM_SVC_PSA_CLOSE:
944947
tfm_svcall_psa_close(ctx, 0);
945948
break;

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ uint32_t SVCHandler_main(uint32_t *svc_args, uint32_t lr)
205205
case TFM_SVC_PSA_NOTIFY:
206206
case TFM_SVC_PSA_CLEAR:
207207
case TFM_SVC_PSA_EOI:
208-
svc_args[0] = SVC_Handler_IPC(svc_number, svc_args);
208+
svc_args[0] = SVC_Handler_IPC(svc_number, svc_args, lr);
209209
break;
210210
#endif
211211
default:

0 commit comments

Comments
 (0)