Skip to content

Commit c4ad77f

Browse files
committed
Make RAM regions non-executable
This commit makes the privileged RAM and stack regions non-executable. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent acd9279 commit c4ad77f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

portable/GCC/ARM_CM3_MPU/port.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ static void prvSetupMPU( void )
637637

638638
portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
639639
( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
640+
( portMPU_REGION_EXECUTE_NEVER ) |
640641
prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
641642
( portMPU_REGION_ENABLE );
642643

@@ -736,6 +737,7 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
736737
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
737738
( portMPU_REGION_READ_WRITE ) |
738739
( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
740+
( portMPU_REGION_EXECUTE_NEVER ) |
739741
( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
740742
( portMPU_REGION_ENABLE );
741743

@@ -761,7 +763,8 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
761763
( portSTACK_REGION ); /* Region number. */
762764

763765
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
764-
( portMPU_REGION_READ_WRITE ) | /* Read and write. */
766+
( portMPU_REGION_READ_WRITE ) |
767+
( portMPU_REGION_EXECUTE_NEVER ) |
765768
( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
766769
( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
767770
( portMPU_REGION_ENABLE );

portable/GCC/ARM_CM4_MPU/port.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ static void prvSetupMPU( void )
723723
( portPRIVILEGED_RAM_REGION );
724724

725725
portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
726+
( portMPU_REGION_EXECUTE_NEVER ) |
726727
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
727728
prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
728729
( portMPU_REGION_ENABLE );
@@ -834,6 +835,7 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
834835

835836
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
836837
( portMPU_REGION_READ_WRITE ) |
838+
( portMPU_REGION_EXECUTE_NEVER ) |
837839
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
838840
( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
839841
( portMPU_REGION_ENABLE );
@@ -860,7 +862,8 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
860862
( portSTACK_REGION ); /* Region number. */
861863

862864
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
863-
( portMPU_REGION_READ_WRITE ) | /* Read and write. */
865+
( portMPU_REGION_READ_WRITE ) |
866+
( portMPU_REGION_EXECUTE_NEVER ) |
864867
( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
865868
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
866869
( portMPU_REGION_ENABLE );

portable/IAR/ARM_CM4F_MPU/port.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ static void prvSetupMPU( void )
562562
( portPRIVILEGED_RAM_REGION );
563563

564564
portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
565+
( portMPU_REGION_EXECUTE_NEVER ) |
565566
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
566567
prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
567568
( portMPU_REGION_ENABLE );
@@ -631,6 +632,7 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
631632

632633
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
633634
( portMPU_REGION_READ_WRITE ) |
635+
( portMPU_REGION_EXECUTE_NEVER ) |
634636
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
635637
( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
636638
( portMPU_REGION_ENABLE );
@@ -657,7 +659,8 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
657659
( portSTACK_REGION ); /* Region number. */
658660

659661
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
660-
( portMPU_REGION_READ_WRITE ) | /* Read and write. */
662+
( portMPU_REGION_READ_WRITE ) |
663+
( portMPU_REGION_EXECUTE_NEVER ) |
661664
( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
662665
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
663666
( portMPU_REGION_ENABLE );

portable/RVDS/ARM_CM4_MPU/port.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ static void prvSetupMPU( void )
726726
( portPRIVILEGED_RAM_REGION );
727727

728728
portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
729+
( portMPU_REGION_EXECUTE_NEVER ) |
729730
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
730731
prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
731732
( portMPU_REGION_ENABLE );
@@ -825,6 +826,7 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
825826

826827
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
827828
( portMPU_REGION_READ_WRITE ) |
829+
( portMPU_REGION_EXECUTE_NEVER ) |
828830
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
829831
( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
830832
( portMPU_REGION_ENABLE );
@@ -851,7 +853,8 @@ void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
851853
( portSTACK_REGION ); /* Region number. */
852854

853855
xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
854-
( portMPU_REGION_READ_WRITE ) | /* Read and write. */
856+
( portMPU_REGION_READ_WRITE ) |
857+
( portMPU_REGION_EXECUTE_NEVER ) |
855858
( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
856859
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
857860
( portMPU_REGION_ENABLE );

0 commit comments

Comments
 (0)