Skip to content

Commit

Permalink
Remove local stack variable form MPU wrappers
Browse files Browse the repository at this point in the history
It was possible for a third party that had already independently gained
the ability to execute injected code to achieve further privilege
escalation by branching directly inside a FreeRTOS MPU API wrapper
function with a manually crafted stack frame. This commit removes the
local stack variable `xRunningPrivileged` so that a manually crafted
stack frame cannot be used for privilege escalation by branching
directly inside a FreeRTOS MPU API wrapper.

We thank Certibit Consulting, LLC, Huazhong University of Science and
Technology and the SecLab team at Northeastern University for reporting
this issue.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
  • Loading branch information
aggarg committed Sep 16, 2022
1 parent c2d616e commit 79704b8
Show file tree
Hide file tree
Showing 7 changed files with 1,693 additions and 490 deletions.
2 changes: 0 additions & 2 deletions .github/lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,6 @@ vportgetheapstats
vportinitialiseblocks
vportisrstartfirststask
vportraisebasepri
vportresetprivilege
vportsetmpuregistersetone
vportsetuptimerinterrupt
vportstartfirststask
Expand Down Expand Up @@ -2872,7 +2871,6 @@ xperiod
xportgetcoreid
xportgetfreeheapsize
xportinstallinterrupthandler
xportraiseprivilege
xportregistercinterrupthandler
xportregisterdump
xportstartfirsttask
Expand Down
30 changes: 0 additions & 30 deletions include/mpu_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,6 @@
#define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
#define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )

/**
* @brief Calls the port specific code to raise the privilege.
*
* Sets xRunningPrivileged to pdFALSE if privilege was raised, else sets
* it to pdTRUE.
*/
#define xPortRaisePrivilege( xRunningPrivileged ) \
{ \
/* Check whether the processor is already privileged. */ \
( xRunningPrivileged ) = portIS_PRIVILEGED(); \
\
/* If the processor is not already privileged, raise privilege. */ \
if( ( xRunningPrivileged ) == pdFALSE ) \
{ \
portRAISE_PRIVILEGE(); \
} \
}

/**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific
* code to reset the privilege, otherwise does nothing.
*/
#define vPortResetPrivilege( xRunningPrivileged ) \
{ \
if( ( xRunningPrivileged ) == pdFALSE ) \
{ \
portRESET_PRIVILEGE(); \
} \
}

#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */

#else /* portUSING_MPU_WRAPPERS */
Expand Down
Loading

0 comments on commit 79704b8

Please sign in to comment.