Allow start scheduler and free context SVC from privileged code only (#1475)

Allow start scheduler and free context SVC from privileged code only

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
Kody Stribrny 2026-08-21 10:24:35 -07:00 • committed by GitHub
parent a0e2097c6a
commit 3ca84562d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 1717 additions and 799 deletions

View file

@ -290,9 +290,12 @@ secureportNON_SECURE_CALLABLE void SecureContext_FreeContext( SecureContextHandl
void * pvTaskHandle )
{
uint32_t ulIPSR, ulSecureContextIndex;
uint8_t * pucStackLimit;
/* Read the Interrupt Program Status Register (IPSR) value. */
/* Read the Interrupt Program Status Register (IPSR) and Process Stack Limit
* Register (PSPLIM) value. */
secureportREAD_IPSR( ulIPSR );
secureportREAD_PSPLIM( pucStackLimit );
/* Do nothing if the processor is running in the Thread Mode. IPSR is zero
* when the processor is running in the Thread Mode. */
@ -304,8 +307,14 @@ secureportNON_SECURE_CALLABLE void SecureContext_FreeContext( SecureContextHandl
ulSecureContextIndex = xSecureContextHandle - 1UL;
/* Ensure that the secure context being deleted is associated with
* the task. */
if( xSecureContexts[ ulSecureContextIndex ].pvTaskHandle == pvTaskHandle )
* the task and is NOT the currently-loaded context. Freeing a
* context whose stack is currently loaded in PSPLIM would leave the
* running task referencing freed secure memory (use-after-free).
* pvTaskHandle is supplied by the non-secure side and is untrusted,
* so it is used only as an additional ownership match, not as
* authority. */
if( ( xSecureContexts[ ulSecureContextIndex ].pvTaskHandle == pvTaskHandle ) &&
( xSecureContexts[ ulSecureContextIndex ].pucStackLimit != pucStackLimit ) )
{
/* Free the stack space. */
vPortFree( xSecureContexts[ ulSecureContextIndex ].pucStackLimit );