Mbedtls v2 on IDF v5.1

Hamzah Hajeir
Posts: 11
Joined: Tue Dec 27, 2022 6:02 pm

Mbedtls v2 on IDF v5.1

Postby Hamzah Hajeir » Mon Jan 22, 2024 6:34 pm

Hi there,

I'm facing a very strange bug that causes InstrFetchProhibited or IllegalInstruction exceptions on ESP32's on a code that runs:
- GCC 12.2.0
- ESP-IDF v5.1
- Mbedtls v3.4
- Esp-Lwip v2.1.3
- Arduino Core v3 (Custom build)

Wherein the bug comes when the application tries to call `pbuf_free()` of newly received data that have been decrypted by mbedtls.

The calls heirarchy is lwip tcp->altcp_tls->mbedtls->altcp_tls->application

However, I'm trying to narrow down the issue, as it was not an issue for the older major versions:
- GCC 8.4.0
- ESP-IDF v4.4.5
- Mbedtls v2.28.3
- Esp-Lwip v2.1.2
- Arduino Core v2 (Custom build)

However, I maintain a branch of esp-lwip, had to tweak little bits in altcp_tls_mbedtls file to cope with mbedtls major changes.
Other codes (pbuf.c) isn't changed lately (See https://github.com/espressif/esp-lwip/c ... ore/pbuf.c).

I'm suspecting the mbedtls to be the major root of the bug, as:
- Tried to compile the prior with GCC 12.2.0, and it worked as expected.
- Tried to build with no TLS (Plain TCP), it worked.

However, I tried to make a small testbed without Arduino (small esp-idf project on vscode), couldn't get the TCP working without LoadProhibited bug on the first received TCP data (`pbuf_copy_partial()` that copies the received data to an allocated memory).

The bug comes just after receiving the decrypted data by the mbedtls (Over the`mbedtls_ssl_read()` call).

So, to narrow down the issue, is there a way to compile mbedtls v2.28.3 to esp-idf v5.1, or it's not recommended/not possible?

And what do you think for the bug?

Note: Here's the modified lwip pointing to the patched altcp_tls_mbedtls (https://github.com/HamzaHajeir/esp-lwip ... _mbedtls.c), it doesn't hold the applied patches to cope with mbedtls 3.4.0 yet, but it has a similar state to the patched esp-lwip v2.1.2.

Who is online

Users browsing this forum: No registered users and 98 guests