Skip to content

Commit 331362d

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 <aggarg@amazon.com>
1 parent 79704b8 commit 331362d

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
@@ -120,13 +120,10 @@
120120
#endif
121121

122122
/* Map standard timer.h API functions to the MPU equivalents. */
123-
#define xTimerCreate MPU_xTimerCreate
124-
#define xTimerCreateStatic MPU_xTimerCreateStatic
125123
#define pvTimerGetTimerID MPU_pvTimerGetTimerID
126124
#define vTimerSetTimerID MPU_vTimerSetTimerID
127125
#define xTimerIsTimerActive MPU_xTimerIsTimerActive
128126
#define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
129-
#define xTimerPendFunctionCall MPU_xTimerPendFunctionCall
130127
#define pcTimerGetName MPU_pcTimerGetName
131128
#define vTimerSetReloadMode MPU_vTimerSetReloadMode
132129
#define uxTimerGetReloadMode MPU_uxTimerGetReloadMode

portable/Common/mpu_wrappers.c

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
portRAISE_PRIVILEGE();
6666
portMEMORY_BARRIER();
6767

68+
uxPriority = uxPriority & ~( portPRIVILEGE_BIT );
69+
portMEMORY_BARRIER();
70+
6871
xReturn = xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask );
6972
portMEMORY_BARRIER();
7073

@@ -97,6 +100,9 @@
97100
portRAISE_PRIVILEGE();
98101
portMEMORY_BARRIER();
99102

103+
uxPriority = uxPriority & ~( portPRIVILEGE_BIT );
104+
portMEMORY_BARRIER();
105+
100106
xReturn = xTaskCreateStatic( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer );
101107
portMEMORY_BARRIER();
102108

@@ -1708,67 +1714,6 @@
17081714
}
17091715
/*-----------------------------------------------------------*/
17101716

1711-
#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) )
1712-
TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName,
1713-
const TickType_t xTimerPeriodInTicks,
1714-
const UBaseType_t uxAutoReload,
1715-
void * const pvTimerID,
1716-
TimerCallbackFunction_t pxCallbackFunction ) /* FREERTOS_SYSTEM_CALL */
1717-
{
1718-
TimerHandle_t xReturn;
1719-
1720-
if( portIS_PRIVILEGED() == pdFALSE )
1721-
{
1722-
portRAISE_PRIVILEGE();
1723-
portMEMORY_BARRIER();
1724-
1725-
xReturn = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction );
1726-
portMEMORY_BARRIER();
1727-
1728-
portRESET_PRIVILEGE();
1729-
portMEMORY_BARRIER();
1730-
}
1731-
else
1732-
{
1733-
xReturn = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction );
1734-
}
1735-
1736-
return xReturn;
1737-
}
1738-
#endif /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1739-
/*-----------------------------------------------------------*/
1740-
1741-
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) )
1742-
TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName,
1743-
const TickType_t xTimerPeriodInTicks,
1744-
const UBaseType_t uxAutoReload,
1745-
void * const pvTimerID,
1746-
TimerCallbackFunction_t pxCallbackFunction,
1747-
StaticTimer_t * pxTimerBuffer ) /* FREERTOS_SYSTEM_CALL */
1748-
{
1749-
TimerHandle_t xReturn;
1750-
1751-
if( portIS_PRIVILEGED() == pdFALSE )
1752-
{
1753-
portRAISE_PRIVILEGE();
1754-
portMEMORY_BARRIER();
1755-
1756-
xReturn = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
1757-
portMEMORY_BARRIER();
1758-
1759-
portRESET_PRIVILEGE();
1760-
portMEMORY_BARRIER();
1761-
}
1762-
else
1763-
{
1764-
xReturn = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
1765-
}
1766-
1767-
return xReturn;
1768-
}
1769-
#endif /* if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1770-
/*-----------------------------------------------------------*/
1771-
17721717
#if ( configUSE_TIMERS == 1 )
17731718
void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ) /* FREERTOS_SYSTEM_CALL */
17741719
{
@@ -1870,35 +1815,6 @@
18701815
#endif /* if ( configUSE_TIMERS == 1 ) */
18711816
/*-----------------------------------------------------------*/
18721817

1873-
#if ( ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
1874-
BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
1875-
void * pvParameter1,
1876-
uint32_t ulParameter2,
1877-
TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */
1878-
{
1879-
BaseType_t xReturn;
1880-
1881-
if( portIS_PRIVILEGED() == pdFALSE )
1882-
{
1883-
portRAISE_PRIVILEGE();
1884-
portMEMORY_BARRIER();
1885-
1886-
xReturn = xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
1887-
portMEMORY_BARRIER();
1888-
1889-
portRESET_PRIVILEGE();
1890-
portMEMORY_BARRIER();
1891-
}
1892-
else
1893-
{
1894-
xReturn = xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
1895-
}
1896-
1897-
return xReturn;
1898-
}
1899-
#endif /* if ( ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
1900-
/*-----------------------------------------------------------*/
1901-
19021818
#if ( configUSE_TIMERS == 1 )
19031819
void MPU_vTimerSetReloadMode( TimerHandle_t xTimer,
19041820
const UBaseType_t uxAutoReload ) /* FREERTOS_SYSTEM_CALL */

0 commit comments

Comments
 (0)