Kazimierz Król
Kazimierz Król

Reputation: 51

How to add sanitizer support to STM32 ARM GCC?

I am working on a large embedded system (STM32F423 CPU and CubeIDE environment on Windows, all the code is in C), and recently I found out that there must be a buffer overflow somewhere. The mbedtls library reports an error suggesting the server did not respond in the required time. The thing is that when I comment one function I added recently (completely unrelated, and not even executed before the error occurs), everything works fine. I think the presence of the function causes the memory arrangement to shift, and some other code has a buffer overflow bug, that overwrites some variable in the mbedtls library. Mbedtls then sends some invalid data to the server, and the server does not respond. That's my guess.

I tried updating mbedtls to the newest version. I also tried to find problematic pointer operations by:

The last thing is problematic, because it triggers the compiler error:

arm-none-eabi-gcc: fatal error: cannot read spec file 'libsanitizer.spec': No such file or directory

Do you know how to add the sanitizer support to the GCC in the CubeIDE toolchain?

I have also got a suggestion to use git bisect, and I am yet going to try it, although my hopes are not high, because most likely the bug has been introduced a long time ago, and the revision where it was introduced will work fine, because of different memory arrangement.

Also having the sanitizer would help finding other pointer issues I might have and not know about.

Upvotes: 5

Views: 2556

Answers (1)

outis
outis

Reputation: 77420

While the documentation for GCC's AddressSanitizer lists ARM as a supported platform, it's only for Android. The same is true for CLang's AddressSanitizer.

To add support, you'd need to port an ASAN run-time library (such as the Android, GCC or LLVM libraries) and define the .spec file. The exact process in its entirety is beyond the scope of SO, though specific issues that could crop up may be on-topic.

Upvotes: 2

Related Questions