From 59ba98b2e3f4e8abe745e7e239c84575eecbd73b Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Tue, 17 Oct 2023 19:59:37 +0530 Subject: [PATCH 1/2] Fix reliability issues in CMake sample (#835) * Fix reliability issues in CMake example sample. --- cmake_example/main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmake_example/main.c b/cmake_example/main.c index f0eaf1cf1ba..d00aeae7206 100644 --- a/cmake_example/main.c +++ b/cmake_example/main.c @@ -52,6 +52,9 @@ static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; void exampleTask( void * parameters ) { + /* Unused parameters. */ + ( void ) parameters; + for( ; ; ) { /* Example Task Code */ @@ -59,7 +62,7 @@ void exampleTask( void * parameters ) } } -int main( void ) +void main( void ) { printf( "Example FreeRTOS Project\n" ); @@ -71,19 +74,22 @@ int main( void ) exampleTaskStack, &exampleTaskTCB ); + /* Start the scheduler. */ vTaskStartScheduler(); - /* should never get here. */ for( ; ; ) { + /* Should not reach here. */ } - - return 0; } void vApplicationStackOverflowHook( TaskHandle_t xTask, char * pcTaskName ) { + /* Check pcTaskName for the name of the offending task, + * or pxCurrentTCB if pcTaskName has itself been corrupted. */ + ( void ) xTask; + ( void ) pcTaskName; } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, From 4ada1d7d5e853f0f9415dc99cafae72eaf571b59 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:31:43 +0530 Subject: [PATCH 2/2] Fix possible integer overflow (#836) * Fix possible integer overflow --------- Signed-off-by: Gaurav Aggarwal --- portable/Common/mpu_wrappers_v2.c | 41 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/portable/Common/mpu_wrappers_v2.c b/portable/Common/mpu_wrappers_v2.c index 0f2dc654b31..30efa077338 100644 --- a/portable/Common/mpu_wrappers_v2.c +++ b/portable/Common/mpu_wrappers_v2.c @@ -112,6 +112,16 @@ */ #define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET ) +/** + * @brief Max value that fits in a size_t type. + */ + #define mpuSIZE_MAX ( ~( ( size_t ) 0 ) ) + +/** + * @brief Check if multiplying a and b will result in overflow. + */ + #define mpuMULTIPLY_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuSIZE_MAX / ( a ) ) ) ) + /** * @brief Get the index of a free slot in the kernel object pool. * @@ -1035,25 +1045,28 @@ UBaseType_t uxArraySize, configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */ { - UBaseType_t uxReturn = pdFALSE; + UBaseType_t uxReturn = 0; UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE; UBaseType_t xIsTotalRunTimeWriteable = pdFALSE; - xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray, - sizeof( TaskStatus_t ) * uxArraySize, - tskMPU_WRITE_PERMISSION ); - - if( pulTotalRunTime != NULL ) + if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 ) { - xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime, - sizeof( configRUN_TIME_COUNTER_TYPE ), - tskMPU_WRITE_PERMISSION ); - } + xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray, + sizeof( TaskStatus_t ) * uxArraySize, + tskMPU_WRITE_PERMISSION ); - if( ( xIsTaskStatusArrayWriteable == pdTRUE ) && - ( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) ) - { - uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime ); + if( pulTotalRunTime != NULL ) + { + xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime, + sizeof( configRUN_TIME_COUNTER_TYPE ), + tskMPU_WRITE_PERMISSION ); + } + + if( ( xIsTaskStatusArrayWriteable == pdTRUE ) && + ( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) ) + { + uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime ); + } } return uxReturn;