Skip to content

Commit da73aa6

Browse files
committed
Restrict unpriv task to invoke code with privilege
It was possible for an unprivileged task to invoke any function with privilege by passing it as a parameter to MPU_xTaskCreate, MPU_xTaskCreateStatic, MPU_xTimerCreate, MPU_xTimerCreateStatic, or MPU_xTimerPendFunctionCall. This commit ensures that MPU_xTaskCreate and MPU_xTaskCreateStatic can only create unprivileged tasks. It also removes the following APIs: 1. MPU_xTimerCreate 2. MPU_xTimerCreateStatic 3. MPU_xTimerPendFunctionCall We thank Huazhong University of Science and Technology for reporting this issue. Signed-off-by: Gaurav Aggarwal <[email protected]>
1 parent 51ea2bf commit da73aa6

File tree

2 files changed

+6
-93
lines changed

2 files changed

+6
-93
lines changed

include/mpu_wrappers.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@
117117
#endif
118118

119119
/* Map standard timer.h API functions to the MPU equivalents. */
120-
#define xTimerCreate MPU_xTimerCreate
121-
#define xTimerCreateStatic MPU_xTimerCreateStatic
122120
#define pvTimerGetTimerID MPU_pvTimerGetTimerID
123121
#define vTimerSetTimerID MPU_vTimerSetTimerID
124122
#define xTimerIsTimerActive MPU_xTimerIsTimerActive
125123
#define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
126-
#define xTimerPendFunctionCall MPU_xTimerPendFunctionCall
127124
#define pcTimerGetName MPU_pcTimerGetName
128125
#define vTimerSetReloadMode MPU_vTimerSetReloadMode
129126
#define uxTimerGetReloadMode MPU_uxTimerGetReloadMode

portable/Common/mpu_wrappers.c

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
portRAISE_PRIVILEGE();
6262
portMEMORY_BARRIER();
6363

64+
uxPriority = uxPriority & ~( portPRIVILEGE_BIT );
65+
portMEMORY_BARRIER();
66+
6467
xReturn = xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask );
6568
portMEMORY_BARRIER();
6669

@@ -93,6 +96,9 @@
9396
portRAISE_PRIVILEGE();
9497
portMEMORY_BARRIER();
9598

99+
uxPriority = uxPriority & ~( portPRIVILEGE_BIT );
100+
portMEMORY_BARRIER();
101+
96102
xReturn = xTaskCreateStatic( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer );
97103
portMEMORY_BARRIER();
98104

@@ -1678,67 +1684,6 @@ void MPU_vQueueDelete( QueueHandle_t xQueue ) /* FREERTOS_SYSTEM_CALL */
16781684
}
16791685
/*-----------------------------------------------------------*/
16801686

1681-
#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) )
1682-
TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName,
1683-
const TickType_t xTimerPeriodInTicks,
1684-
const UBaseType_t uxAutoReload,
1685-
void * const pvTimerID,
1686-
TimerCallbackFunction_t pxCallbackFunction ) /* FREERTOS_SYSTEM_CALL */
1687-
{
1688-
TimerHandle_t xReturn;
1689-
1690-
if( portIS_PRIVILEGED() == pdFALSE )
1691-
{
1692-
portRAISE_PRIVILEGE();
1693-
portMEMORY_BARRIER();
1694-
1695-
xReturn = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction );
1696-
portMEMORY_BARRIER();
1697-
1698-
portRESET_PRIVILEGE();
1699-
portMEMORY_BARRIER();
1700-
}
1701-
else
1702-
{
1703-
xReturn = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction );
1704-
}
1705-
1706-
return xReturn;
1707-
}
1708-
#endif /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1709-
/*-----------------------------------------------------------*/
1710-
1711-
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) )
1712-
TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName,
1713-
const TickType_t xTimerPeriodInTicks,
1714-
const UBaseType_t uxAutoReload,
1715-
void * const pvTimerID,
1716-
TimerCallbackFunction_t pxCallbackFunction,
1717-
StaticTimer_t * pxTimerBuffer ) /* FREERTOS_SYSTEM_CALL */
1718-
{
1719-
TimerHandle_t xReturn;
1720-
1721-
if( portIS_PRIVILEGED() == pdFALSE )
1722-
{
1723-
portRAISE_PRIVILEGE();
1724-
portMEMORY_BARRIER();
1725-
1726-
xReturn = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
1727-
portMEMORY_BARRIER();
1728-
1729-
portRESET_PRIVILEGE();
1730-
portMEMORY_BARRIER();
1731-
}
1732-
else
1733-
{
1734-
xReturn = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
1735-
}
1736-
1737-
return xReturn;
1738-
}
1739-
#endif /* if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1740-
/*-----------------------------------------------------------*/
1741-
17421687
#if ( configUSE_TIMERS == 1 )
17431688
void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ) /* FREERTOS_SYSTEM_CALL */
17441689
{
@@ -1840,35 +1785,6 @@ void MPU_vQueueDelete( QueueHandle_t xQueue ) /* FREERTOS_SYSTEM_CALL */
18401785
#endif /* if ( configUSE_TIMERS == 1 ) */
18411786
/*-----------------------------------------------------------*/
18421787

1843-
#if ( ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
1844-
BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
1845-
void * pvParameter1,
1846-
uint32_t ulParameter2,
1847-
TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */
1848-
{
1849-
BaseType_t xReturn;
1850-
1851-
if( portIS_PRIVILEGED() == pdFALSE )
1852-
{
1853-
portRAISE_PRIVILEGE();
1854-
portMEMORY_BARRIER();
1855-
1856-
xReturn = xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
1857-
portMEMORY_BARRIER();
1858-
1859-
portRESET_PRIVILEGE();
1860-
portMEMORY_BARRIER();
1861-
}
1862-
else
1863-
{
1864-
xReturn = xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
1865-
}
1866-
1867-
return xReturn;
1868-
}
1869-
#endif /* if ( ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1870-
/*-----------------------------------------------------------*/
1871-
18721788
#if ( configUSE_TIMERS == 1 )
18731789
void MPU_vTimerSetReloadMode( TimerHandle_t xTimer,
18741790
const UBaseType_t uxAutoReload ) /* FREERTOS_SYSTEM_CALL */

0 commit comments

Comments
 (0)