Skip to content

[Bug]: wolfSSL_free crash on ESP32s3 #6637

@PaulMartinsen

Description

@PaulMartinsen

Contact Details

No response

Version

a026d84 (master branch ca 8:33 am, 15/7/2023)

Description

Calling wolfSSL_free to dispose of a TLS session from a 'cleanup' thread leads to an assertion failure in xQueueGenericSend in esp-idf/v5.0/components/freertos/FreeRTOS-Kernel/queue.c. This seems to occur only when wolfSSL_free is called from a different task to the one that created it. In both case all communication is finished and it is time to free the memory. And wolfSSL_free is only being called once for the session.

Stack trace (below), shows this occurs when esp_sha_hw_unlock calls esp_CryptHwMutexUnLock(&sha_mutex). The same application code operates correctly running on Windows (however, that's not using the Espressif port).

Currently Windows decided it can't find the ESP32s3 JTAG interface, so I haven't been able to look at what's happening in any more detail. Will add new info as it comes to hand.

I'm using this version which is a clean fork from a recent master branch with only trivial changes for building on Windows. @gojimmypi , do you think your new PR might make a difference?

Reproduction steps

No response

Relevant log output

0x4038171d: esp_system_abort at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/components/esp_system/esp_system.c:135
0x40388e65: __assert_func at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/components/newlib/assert.c:78
0x403820ec: xQueueGenericSend at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/components/freertos/FreeRTOS-Kernel/queue.c:837 (discriminator 8)
0x42095433: esp_CryptHwMutexUnLock at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/port/Espressif/esp32_util.c:80
0x42094dd0: esp_sha_hw_unlock at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/port/Espressif/esp32_sha.c:819
0x42094eb5: esp_sha_init_ctx at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/port/Espressif/esp32_sha.c:260 (discriminator 15)
0x42094f62: esp_sha_init at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/port/Espressif/esp32_sha.c:99
0x4208cd9d: InitSha256 at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/sha256.c:771
0x4208d5a6: wc_Sha256Free at k:/Lumos/Vendor/WolfSSL/wolfssl/wolfcrypt/src/sha256.c:1855
0x4209715f: FreeHandshakeHashes at k:/Lumos/Vendor/WolfSSL/wolfssl/src/internal.c:6845
0x42097cc2: SSL_ResourceFree at k:/Lumos/Vendor/WolfSSL/wolfssl/src/internal.c:7929
0x42097e61: FreeSSL at k:/Lumos/Vendor/WolfSSL/wolfssl/src/internal.c:8470
0x420606ba: wolfSSL_free at k:/Lumos/Vendor/WolfSSL/wolfssl/src/ssl.c:1491
0x4204dfef: CTLSSession::Dispose() at k:/Lumos/DeviceWebservicesLibrary/Communications/TLSContext.cpp:77
0x4204e01d: CTLSSession::~CTLSSession() at k:/Lumos/DeviceWebservicesLibrary/Communications/TLSContext.cpp:69
0x4204d249: CTcpConnectionInfo::~CTcpConnectionInfo() at k:/Lumos/DeviceWebservicesLibrary/Communications/TcpConnectionInfo.h:13
 (inlined by) CTcpConnectionInfo::~CTcpConnectionInfo() at k:/Lumos/DeviceWebservicesLibrary/Communications/TcpConnectionInfo.h:13
0x4200bbdf: std::default_delete<CConnectionInfo>::operator()(CConnectionInfo*) const at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/unique_ptr.h:85
 (inlined by) std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >::~unique_ptr() at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/unique_ptr.h:361
 (inlined by) void std::destroy_at<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > >(std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >*) at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/stl_construct.h:88
 (inlined by) void std::allocator_traits<std::allocator<std::_Fwd_list_node<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > > > >::destroy<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > >(std::allocator<std::_Fwd_list_node<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > > >&, std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >*) at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/alloc_traits.h:533
 (inlined by) std::_Fwd_list_base<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >, std::allocator<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > > >::_M_erase_after(std::_Fwd_list_node_base*, std::_Fwd_list_node_base*) at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/forward_list.tcc:86
0x4204c65f: std::_Fwd_list_base<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >, std::allocator<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > > >::~_Fwd_list_base() at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/forward_list.h:346
 (inlined by) std::forward_list<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> >, std::allocator<std::unique_ptr<CConnectionInfo, std::default_delete<CConnectionInfo> > > >::~forward_list() at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/forward_list.h:591
 (inlined by) remove_if<CConnectionManager::DiscardOldConnections(const time_point&)::<lambda(const std::unique_ptr<CConnectionInfo>&)> > at c:\programming\toolchains\visualgdb\esp32\v5\tools\xtensa-esp32s3-elf\esp-2022r1-11.2.0\xtensa-esp32s3-elf\xtensa-esp32s3-elf\include\c++\11.2.0\bits/forward_list.tcc:330
0x4204c6c5: CConnectionManager::DiscardOldConnections(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long long, std::ratio<1ll, 1000000000ll> > > const&) at k:/Lumos/DeviceWebservicesLibrary/Communications/ConnectionManager.cpp:200
0x4204c779: CConnectionManager::Process() at k:/Lumos/DeviceWebservicesLibrary/Communications/ConnectionManager.cpp:161
0x4204e639: non-virtual thunk to CConnectionFactory::Process() at k:/Lumos/DeviceWebservicesLibrary/Services/ConnectionFactory.h:54
0x4216b0f5: CManualBackgroundTaskDispatcher::RunEachTaskOnce() at k:/Lumos/DeviceWebservicesLibrary/Services/ManualBackgroundTaskDispatcher.cpp:21
0x4200c354: app_main at C:\Users\Paul\Projects\BLS\FPH Projects\2022 SDC\Software\Lumos\Lumos32i\build\VisualGDB\Debug/../../../main/Lumos32i.cpp:544
0x42174c2b: main_task at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/components/freertos/FreeRTOS-Kernel/portable/port_common.c:131 (discriminator 2)
0x403856f5: vPortTaskWrapper at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:151

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions