From d9fc48bced1ecb9aeebd8ee0d564a5eb6405afe6 Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:21:27 +0530 Subject: [PATCH] Backport PR 839 to FreeRTOS-Kernel V10.6.1 (#840) * Fix size alignment in the integer overflow issue * Remove CORTEX_M3_MPS2_QEMU demo in the V10.6.x branch to sync with the main branch. --- .github/workflows/kernel-demos.yml | 14 -------------- portable/Common/mpu_wrappers_v2.c | 14 ++++++++------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/.github/workflows/kernel-demos.yml b/.github/workflows/kernel-demos.yml index 865f4eefb..abee44bc1 100644 --- a/.github/workflows/kernel-demos.yml +++ b/.github/workflows/kernel-demos.yml @@ -161,20 +161,6 @@ jobs: working-directory: FreeRTOS/Demo/CORTEX_LM3S102_GCC run: make -j - - name: Build CORTEX_M3_MPS2_QEMU_GCC Demo - shell: bash - working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC - run: | - make clean - make -j - - - name: Build CORTEX_M3_MPS2_QEMU_GCC Demo - shell: bash - working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC - run: | - make clean - make FULL_DEMO=1 -j - - name: Build CORTEX_LM3S811_GCC Demo shell: bash working-directory: FreeRTOS/Demo/CORTEX_LM3S811_GCC diff --git a/portable/Common/mpu_wrappers_v2.c b/portable/Common/mpu_wrappers_v2.c index 2bb1417be..93874eacb 100644 --- a/portable/Common/mpu_wrappers_v2.c +++ b/portable/Common/mpu_wrappers_v2.c @@ -113,14 +113,14 @@ #define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET ) /** - * @brief Max value that fits in a size_t type. + * @brief Max value that fits in a uint32_t type. */ - #define mpuSIZE_MAX ( ~( ( size_t ) 0 ) ) + #define mpuUINT32_MAX ( ~( ( uint32_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 ) ) ) ) + #define mpuMULTIPLY_UINT32_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuUINT32_MAX / ( a ) ) ) ) /** * @brief Get the index of a free slot in the kernel object pool. @@ -937,11 +937,13 @@ UBaseType_t uxReturn = 0; UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE; UBaseType_t xIsTotalRunTimeWriteable = pdFALSE; + uint32_t ulArraySize = ( uint32_t ) uxArraySize; + uint32_t ulTaskStatusSize = ( uint32_t ) sizeof( TaskStatus_t ); - if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 ) + if( mpuMULTIPLY_UINT32_WILL_OVERFLOW( ulTaskStatusSize, ulArraySize ) == 0 ) { xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray, - sizeof( TaskStatus_t ) * uxArraySize, + ulTaskStatusSize * ulArraySize, tskMPU_WRITE_PERMISSION ); if( pulTotalRunTime != NULL ) @@ -954,7 +956,7 @@ if( ( xIsTaskStatusArrayWriteable == pdTRUE ) && ( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) ) { - uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime ); + uxReturn = uxTaskGetSystemState( pxTaskStatusArray, ( UBaseType_t ) ulArraySize, pulTotalRunTime ); } }