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
pull/10067/head
Michael Schwarcz 2019-03-11 09:03:40 +02:00 committed by Cruz Monrreal II
parent 64530095b9
commit 0ac2cd377f
3 changed files with 18 additions and 13 deletions

View File

@ -58,6 +58,7 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller);
* handle, in_vec, in_len, out_vec, out_len. * handle, in_vec, in_len, out_vec, out_len.
* \param[in] ns_caller If 'non-zero', call from non-secure client. * \param[in] ns_caller If 'non-zero', call from non-secure client.
* Or from secure client. * Or from secure client.
* \param[in] lr Link register to be stored
* *
* \retval >=0 RoT Service-specific status value. * \retval >=0 RoT Service-specific status value.
* \retval <0 RoT Service-specific error code. * \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);
* \arg The message is unrecognized by the RoT * \arg The message is unrecognized by the RoT
* Service or incorrectly formatted. * Service or incorrectly formatted.
*/ */
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller); psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr);
/** /**
* \brief SVC handler for \ref psa_close. * \brief SVC handler for \ref psa_close.
@ -96,10 +97,11 @@ void tfm_svcall_psa_close(uint32_t *args, int32_t ns_caller);
* *
* \param[in] svc_num SVC number * \param[in] svc_num SVC number
* \param[in] ctx Argument context * \param[in] ctx Argument context
* \param[in] lr Link register to be stored
* *
* \returns Return values from those who has, * \returns Return values from those who has,
* or PSA_SUCCESS. * or PSA_SUCCESS.
*/ */
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx); int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr);
#endif #endif

View File

@ -107,7 +107,7 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller)
return PSA_NULL_HANDLE; return PSA_NULL_HANDLE;
} }
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller) psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr)
{ {
psa_handle_t handle; psa_handle_t handle;
psa_invec *inptr, invecs[PSA_MAX_IOVEC]; 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)
in_num = (size_t)args[2]; in_num = (size_t)args[2];
outptr = (psa_outvec *)args[3]; outptr = (psa_outvec *)args[3];
/* /*
* FixMe: 5th parameter is pushed at stack top before SVC; plus * 5th parameter is pushed at stack top before SVC; plus exception stacked contents,
* exception stacked contents, 5th parameter is now at 8th position * 5th parameter is now at 8th position in SVC handler.
* in SVC handler. However, if thread mode applies FloatPoint, then * However, if thread mode applies FloatPoint, then FloatPoint context is pushed into
* FloatPoint context is pushed into stack and then 5th parameter * stack and then 5th parameter will be args[26].
* will not be args[8].
* Will refine it later.
*/ */
out_num = (size_t)args[8]; if (lr & EXC_RETURN_FPU_FRAME_BASIC) {
out_num = (size_t)args[8];
}
else {
out_num = (size_t)args[26];
}
} else { } else {
/* /*
* FixMe: From non-secure caller, vec and len are composed into a new * 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)
/* FixMe: re-enable interrupt */ /* FixMe: re-enable interrupt */
} }
int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx) int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr)
{ {
switch (svc_num) { switch (svc_num) {
case TFM_SVC_SCHEDULE: case TFM_SVC_SCHEDULE:
@ -939,7 +942,7 @@ int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx)
case TFM_SVC_PSA_CONNECT: case TFM_SVC_PSA_CONNECT:
return tfm_svcall_psa_connect(ctx, 0); return tfm_svcall_psa_connect(ctx, 0);
case TFM_SVC_PSA_CALL: case TFM_SVC_PSA_CALL:
return tfm_svcall_psa_call(ctx, 0); return tfm_svcall_psa_call(ctx, 0, lr);
case TFM_SVC_PSA_CLOSE: case TFM_SVC_PSA_CLOSE:
tfm_svcall_psa_close(ctx, 0); tfm_svcall_psa_close(ctx, 0);
break; break;

View File

@ -205,7 +205,7 @@ uint32_t SVCHandler_main(uint32_t *svc_args, uint32_t lr)
case TFM_SVC_PSA_NOTIFY: case TFM_SVC_PSA_NOTIFY:
case TFM_SVC_PSA_CLEAR: case TFM_SVC_PSA_CLEAR:
case TFM_SVC_PSA_EOI: case TFM_SVC_PSA_EOI:
svc_args[0] = SVC_Handler_IPC(svc_number, svc_args); svc_args[0] = SVC_Handler_IPC(svc_number, svc_args, lr);
break; break;
#endif #endif
default: default: