diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 1472c0c86..83ca1bbe8 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -1,3 +1,13 @@ +## Threat model + +Before reporting an issue, please review the FreeRTOS kernel threat model. It +describes the security assumptions the kernel makes, which threats are in scope, +and the protections the kernel does and does not provide. Understanding these +boundaries helps determine whether an observed behavior is a security +vulnerability or expected, documented behavior. + +- [FreeRTOS Kernel Threat Model](https://www.freertos.org/Security/02-Kernel-threat-model) + ## Reporting a Vulnerability If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security diff --git a/include/task.h b/include/task.h index 2a19fa73f..2add58b94 100644 --- a/include/task.h +++ b/include/task.h @@ -1050,7 +1050,7 @@ UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNC * * @return The base priority of xTask. * - * \defgroup uxTaskPriorityGet uxTaskBasePriorityGet + * \defgroup uxTaskBasePriorityGet uxTaskBasePriorityGet * \ingroup TaskCtrl */ UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; diff --git a/portable/GCC/ARM_CM3_MPU/port.c b/portable/GCC/ARM_CM3_MPU/port.c index 8c4dd7800..c8d3439b6 100644 --- a/portable/GCC/ARM_CM3_MPU/port.c +++ b/portable/GCC/ARM_CM3_MPU/port.c @@ -55,9 +55,19 @@ #define portNVIC_SYSTICK_CLK ( 0 ) #endif +/* Unprivileged critical sections are not supported when using MPU wrappers + * version 2. Default the option to 0 and reject an explicit value of 1. */ #ifndef configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS - #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." - #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0 + #else + #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #endif +#else + #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) ) + #error configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not supported with MPU wrappers version 2 ( configUSE_MPU_WRAPPERS_V1 == 0 ). + #endif #endif /* Prototype of all Interrupt Service Routines (ISRs). */ diff --git a/portable/GCC/ARM_CM4_MPU/port.c b/portable/GCC/ARM_CM4_MPU/port.c index 79f5e76d5..5a3527157 100644 --- a/portable/GCC/ARM_CM4_MPU/port.c +++ b/portable/GCC/ARM_CM4_MPU/port.c @@ -59,9 +59,19 @@ #define portNVIC_SYSTICK_CLK ( 0 ) #endif +/* Unprivileged critical sections are not supported when using MPU wrappers + * version 2. Default the option to 0 and reject an explicit value of 1. */ #ifndef configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS - #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." - #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0 + #else + #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #endif +#else + #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) ) + #error configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not supported with MPU wrappers version 2 ( configUSE_MPU_WRAPPERS_V1 == 0 ). + #endif #endif /* Prototype of all Interrupt Service Routines (ISRs). */ diff --git a/portable/IAR/ARM_CM4F_MPU/port.c b/portable/IAR/ARM_CM4F_MPU/port.c index 720138f08..0441e0f0c 100644 --- a/portable/IAR/ARM_CM4F_MPU/port.c +++ b/portable/IAR/ARM_CM4F_MPU/port.c @@ -66,9 +66,19 @@ #define portNVIC_SYSTICK_CLK_BIT ( 0 ) #endif +/* Unprivileged critical sections are not supported when using MPU wrappers + * version 2. Default the option to 0 and reject an explicit value of 1. */ #ifndef configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS - #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." - #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0 + #else + #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #endif +#else + #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) ) + #error configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not supported with MPU wrappers version 2 ( configUSE_MPU_WRAPPERS_V1 == 0 ). + #endif #endif /* Prototype of all Interrupt Service Routines (ISRs). */ diff --git a/portable/RVDS/ARM_CM4_MPU/port.c b/portable/RVDS/ARM_CM4_MPU/port.c index 450b86211..8620325ca 100644 --- a/portable/RVDS/ARM_CM4_MPU/port.c +++ b/portable/RVDS/ARM_CM4_MPU/port.c @@ -48,9 +48,19 @@ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE +/* Unprivileged critical sections are not supported when using MPU wrappers + * version 2. Default the option to 0 and reject an explicit value of 1. */ #ifndef configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS - #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." - #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0 + #else + #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security." + #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 1 + #endif +#else + #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) ) + #error configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not supported with MPU wrappers version 2 ( configUSE_MPU_WRAPPERS_V1 == 0 ). + #endif #endif /* Prototype of all Interrupt Service Routines (ISRs). */ diff --git a/tasks.c b/tasks.c index b0299d12b..461271fcf 100644 --- a/tasks.c +++ b/tasks.c @@ -7362,7 +7362,7 @@ STATIC void prvResetNextTaskUnblockTime( void ) /* MISRA Ref 11.5.1 [Malloc memory assignment] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */ /* coverity[misra_c_2012_rule_11_5_violation] */ - pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); + pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) ); if( pxTaskStatusArray != NULL ) { @@ -7531,7 +7531,7 @@ STATIC void prvResetNextTaskUnblockTime( void ) /* MISRA Ref 11.5.1 [Malloc memory assignment] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */ /* coverity[misra_c_2012_rule_11_5_violation] */ - pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); + pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) ); if( pxTaskStatusArray != NULL ) {