esp-idf: Assert failure in esp_bignum.c (IDFGH-8991)
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
v5.0
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
Development Kit.
ESP32-WROOM-32
Power Supply used.
Battery
What is the expected behavior?
No assert failure.
What is the actual behavior?
My ESP connects to a MQTT server aends a few messages, goes to deep sleep for a while and then starts the process again. Once in a while (maybe one a day?) I get a panic reset. Since I store the Core Dumps on a SD card I could check the Stack trace and identify the assert here (https://github.com/espressif/esp-idf/blob/master/components/mbedtls/port/esp_bignum.c#L651) was causing the panic.
Steps to reproduce.
Connect to an MQTT Broker over SSL and wait?
Debug Logs.
#0 0x40081b71 in panic_abort (details=0x3ffca220 "assert failed: 0x40125699") at /opt/esp/idf/components/esp_system/panic.c:412
#1 0x4008ad34 in esp_system_abort (details=0x3ffca220 "assert failed: 0x40125699") at /opt/esp/idf/components/esp_system/esp_system.c:135
#2 0x40091a51 in __assert_func (file=0x0, line=0, func=0x0, expr=0x0) at /opt/esp/idf/components/newlib/assert.c:40
#3 0x4012569c in mpi_mult_mpi_failover_mod_mult (z_words=<optimized out>, Y=<optimized out>, X=<optimized out>, Z=<optimized out>) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:651
#4 mbedtls_mpi_mul_mpi (Z=<optimized out>, X=<optimized out>, Y=<optimized out>) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:522
#5 0x4012577c in mbedtls_mpi_mul_int (X=0x3ffca2d8, A=0x3ffca2f0, b=934139769) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:557
#6 0x4011a1f7 in mbedtls_mpi_div_mpi (Q=0x0, R=0x3ffd2ff8, A=0x3ffca390, B=0x3ffd2f98) at /opt/esp/idf/components/mbedtls/mbedtls/library/bignum.c:1690
#7 0x4011a3e1 in mbedtls_mpi_mod_mpi (R=0x3ffd2ff8, A=0x3ffca390, B=0x3ffd2f98) at /opt/esp/idf/components/mbedtls/mbedtls/library/bignum.c:1760
#8 0x40125158 in calculate_rinv (Rinv=0x3ffd2ff8, M=0x3ffd2f98, num_words=64) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:200
#9 0x40125389 in esp_mpi_exp_mod (_Rinv=0x3ffd2ff8, M=0x3ffd2f98, Y=0x3ffd2fa4, X=0x3ffca450, Z=0x3ffca450) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:388
#10 mbedtls_mpi_exp_mod (X=0x3ffca450, A=0x3ffca450, E=0x3ffd2fa4, N=0x3ffd2f98, _RR=0x3ffd2ff8) at /opt/esp/idf/components/mbedtls/port/esp_bignum.c:460
#11 0x401234d6 in mbedtls_rsa_public (ctx=0x3ffd2f90, input=<optimized out>, output=0x3ffd4c60 <error: Cannot access memory at address 0x3ffd4c60>) at /opt/esp/idf/components/mbedtls/mbedtls/library/rsa.c:763
#12 0x40124383 in mbedtls_rsa_rsassa_pkcs1_v15_verify (ctx=0x3ffd2f90, md_alg=MBEDTLS_MD_SHA256, hashlen=<optimized out>, hash=0x3ffca540 "u¯ÏÊG¯{tv&d~3q^¹b5÷þ~¯ƒN<)¼\024\231«9\377O\025ý?ü", sig=0x3ffcd469 <error: Cannot access memory at address 0x3ffcd469>)
at /opt/esp/idf/components/mbedtls/mbedtls/library/rsa.c:2154
#13 0x401243ed in mbedtls_rsa_pkcs1_verify (ctx=0x3ffd2f90, md_alg=MBEDTLS_MD_SHA256, hashlen=32, hash=0x3ffca540 "u¯ÏÊG¯{tv&d~3q^¹b5÷þ~¯ƒN<)¼\024\231«9\377O\025ý?ü", sig=0x3ffcd469 <error: Cannot access memory at address 0x3ffcd469>)
at /opt/esp/idf/components/mbedtls/mbedtls/library/rsa.c:2206
#14 0x40121a62 in rsa_verify_wrap (ctx=0x3ffd2f90, md_alg=<optimized out>, hash=0x3ffca540 "u¯ÏÊG¯{tv&d~3q^¹b5÷þ~¯ƒN<)¼\024\231«9\377O\025ý?ü", hash_len=32, sig=0x3ffcd469 <error: Cannot access memory at address 0x3ffcd469>, sig_len=256)
at /opt/esp/idf/components/mbedtls/mbedtls/library/pk_wrap.c:247
#15 0x40121744 in mbedtls_pk_verify_restartable (ctx=0x3ffd29c8, md_alg=MBEDTLS_MD_SHA256, hash=0x3ffca540 "u¯ÏÊG¯{tv&d~3q^¹b5÷þ~¯ƒN<)¼\024\231«9\377O\025ý?ü", hash_len=32, sig=0x3ffcd469 <error: Cannot access memory at address 0x3ffcd469>, sig_len=256,
rs_ctx=rs_ctx@entry=0x0) at /opt/esp/idf/components/mbedtls/mbedtls/library/pk.c:441
#16 0x40117143 in ssl_parse_server_key_exchange (ssl=0x3ffcab58) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls12_client.c:2512
#17 mbedtls_ssl_handshake_client_step (ssl=0x3ffcab58) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls12_client.c:3663
#18 0x40115282 in mbedtls_ssl_handshake_step (ssl=0x3ffcab58) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls.c:3027
#19 mbedtls_ssl_handshake_step (ssl=0x3ffcab58) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls.c:2984
#20 0x401152db in mbedtls_ssl_handshake (ssl=<optimized out>) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls.c:3092
#21 mbedtls_ssl_handshake (ssl=0x3ffcab58) at /opt/esp/idf/components/mbedtls/mbedtls/library/ssl_tls.c:3068
#22 0x40111744 in esp_mbedtls_handshake (tls=0x3ffcab58, cfg=0x3ffc8f8c) at /opt/esp/idf/components/esp-tls/esp_tls_mbedtls.c:192
#23 0x40111408 in esp_tls_handshake (cfg=0x3ffc8f8c, tls=0x3ffcab58) at /opt/esp/idf/components/esp-tls/esp_tls.c:83
#24 esp_tls_low_level_conn (hostname=<optimized out>, hostlen=19, port=<optimized out>, cfg=0x3ffc8f8c, tls=0x3ffcab58) at /opt/esp/idf/components/esp-tls/esp_tls.c:437
#25 0x401114fa in esp_tls_conn_new_sync (hostname=0x3ffc8398 <error: Cannot access memory at address 0x3ffc8398>, hostlen=19, port=8883, cfg=0x3ffc8f8c, tls=0x3ffcab58) at /opt/esp/idf/components/esp-tls/esp_tls.c:464
#26 0x40112cee in ssl_connect (t=0x3ffc8508, host=0x3ffc8398 <error: Cannot access memory at address 0x3ffc8398>, port=8883, timeout_ms=<optimized out>) at /opt/esp/idf/components/tcp_transport/transport_ssl.c:109
#27 0x40176bd0 in esp_transport_connect (t=0x3ffc8508, host=0x3ffc8398 <error: Cannot access memory at address 0x3ffc8398>, port=8883, timeout_ms=10000) at /opt/esp/idf/components/tcp_transport/transport.c:123
#28 0x400e8885 in esp_mqtt_task (pv=0x3ffc8194) at /opt/esp/idf/components/mqtt/esp-mqtt/mqtt_client.c:1489
#29 0x4008dbe0 in vPortTaskWrapper (pxCode=0x400e866c <esp_mqtt_task>, pvParameters=0x3ffc8194) at /opt/esp/idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:151
### More Information.
_No response_
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (7 by maintainers)
@laukik-hase, we haven’t seen the issue these past few weeks while performing various validation tests. We’ll call it resolved on our end for now. At this point, I’m questioning whether or not we originally saw the assert failure on a legitimate setup with your patch applied.
We updated our sdkconfig a while ago to force single-core mode. I’m assuming that shouldn’t have any influence on this assert failiure though.
Yes, I was suggesting this setup.
I managed to create a repro: repro.c.txt sdkconfig.txt
Basically it just a copy and pasted from your samples, combining WIFI and MQTT. It connects to MQTT and then goes to deepsleep for 1 sec. After the deep sleep it connects again.
After running this for a few hours I get an assert failure:
assert failed: mpi_mult_mpi_failover_mod_mult esp_bignum.c:651 (mpi_words(Z) == z_words)This only happens with the attached sdkconfig. Not, for example, when I disable optimization.
v5.0
I already checked to see if I have the fix that prevents the compiler optimization (from https://github.com/espressif/esp-idf/issues/8710)