Closed wouter-palmsens closed 11 months ago
Hello @wouter-palmsens,
Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.
With regards,
ST Internal Reference: 154639
Hello @wouter-palmsens ,
Thank you for this contribution, this point has been reported to our development teams. I will get back to you as soon as I have any updates.
Best Regards,
Note that my remark about violating the strict aliasing rule might not have been entirely correct, but the pointer cast can definitely cause unaligned memory access, which could result in a UsageFault for memory regions that do not support unaligned access (such as the SDRAM).
Fixed in 330a298d637ecfd7f992c14cf154596199501255
Description of the set-up
Description of the bug
The (static) function
HASH_WriteData()
has anuint8_t *
buffer argument, but it reads the data 4 bytes at a time, as can be seen in the code:Note that the pointer cast violates the strict aliasing rule and thus invokes Undefind Behavior, but that's not the real problem here. The actual problem is that more data is read then required in case
Size
is not a multiple of 4. WhenpInBuffer
is at the end of a memory region and not 32-bit aligned, this can cause a BusFault. For example, when the buffer is located at the end of the AXI SRAM on the STM32H753, reading one byte too much will cause the MCU to read from Reserved memory and thus cause a BusFault.The following example code should demonstrate this:
A solution would be to handle the last 1-3 bytes (in case
Size
is not a multiple of 4) separately, thereby avoiding reading out-of-bounds.Screenshots