I tested reading, writing and erasing flash of the highest security tier (secure privileged) from a lower security tier (secure non-privileged). As lower security tiers should not be able to access higher security tiers, this should not be possible if the microcontroller was configured correct according to my understanding. I made a test project with two binaries: bl1 (secure privileged, 0x10000000-0x10008000) and bl2 (secure non-privileged, 0x10008000-0x10010000). The SAU is set so that the flash is secure for both projects.
The secure AHB Controller is configured as follows:
ENABLE_SECURE_CHECKING = 0x1 (ENABLED)
ENABLE_S_PRIV_CHECK = 0x1 (ENABLED)
AHB_SECURE_CTRL->SEC_CTRL_FLASH_ROM[0].SEC_CTRL_FLASH_MEM_RULE[0] = 0x00000023U; (bl1=secure privileged, bl2=secure non-privileged)
With these settings, I expected bl2 (secure non-privileged) not to be able to tamper with the flash
area of bl1 (secure privileged). First I tried to read the memory with the CPU (memcpy) and it worked
as expected: With ENABLE_S_PRIV_CHECK DISABLED I COULD read the memory, with ENABLE_S_PRIV_CHECK I
could NOT read the memory.
However, with ROM API FLASH_Program() and FLASH_Erase(), I am able to make the flash inacessible even with ENABLE_S_PRIV_CHECK ENABLED.
According to my understanding, this should not be possible. secure non-privileged code should
not be able to tamper with secure privileged code, as this is a higher security level.
I attached a test project that demonstrates the behaviour: in bl1/source/tzm_config.c line 13 the
S_PRIV_CHECK can be enabled or disabled. In bl2/source/main.c line 36 the test case (read/write/erase)
can be set. In the current configuration, the flash is destroyed after bl2 runs and then bl1
does not work anymore, i.e. the microcontroller won't do anything as the flash at 0x0 is inaccessible.
I attached the project in case you want to replicate the behaviour.
Am I missing something in the configuration or is this somehow intended behaviour?