Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Bug Reports
  3. ESP32 + Signing fails after xxx msg as result of memory leak

ESP32 + Signing fails after xxx msg as result of memory leak

Scheduled Pinned Locked Moved Bug Reports
esp32signingcryptoesp32 signing faultmbedtlssha256sha256hmac
6 Posts 4 Posters 80 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Technovation
    wrote on last edited by
    #1

    MySensors Version: 2.3.2 (and prior versions)
    Hardware: ESP32

    Summary of Issue: ESP32 in combination with signing enabled will result in signing failure after fixed number of messages (signing events).

    Detailed description:
    I was performing some benchmark tests with different boards in combination with MY_SECURITY_SIMPLE_PASSWD enabled to analyse the impact on message delays (responsiveness). During these tests with an ESP32 (esp32doit-devkit-v1)
    I experienced that the first set of messages were going all OK, but after a while I stopped receiving messages at the controller.

    Diving deeper into the problem I found:

    • The ESP32 was at fault - resetting the device was sufficient to get things running again (for a while)
    • The problem occurs for both ESP32 configured as Gateway or Node
    • It fails repeatably after the same number of messages after a restart of the ESP32 (and the number of successful messages is sketch dependent - e.g. after 520 messages for my GW sketch and 725 messages for my test node).

    Solution:
    quite some steps of debugging later I found that the signing was failing and the root cause appeared to be a memory leak at:

    MyCryptoESP32.cpp in the SHA256 and the SHA256HMAC functions, which perform a
    mbedtls_md_init(&ctx);, but no call to mbedtls_md_free(&ctx); is present to clear the internal structure created at the end of the function.
    After adding mbedtls_md_free(&ctx); at the end of both SHA256 and SHA256HMAC functions the bug appears to be solved (I stopped testing after 133.000 successful messages :grin: ).

    Another point I noticed in my debugging quest is that I also think I spotted a small "typo" in MySigning.cpp in the signerInternalProcessNonceRequest function.
    In the debug message it reports the SGN:NCE:XMT,TO=xxx, where for xxx now the msg.getSender() is being used, but I suppose that should be msg.getDestination(), i.e. the location (= target Node) TO which the nonce is send.

    I initially wanted to try and make (my first) pull request with this fix, but got stranded at the CLA agreement for now (I don't know if my employer will agree to all the terms in the agreement on the patent licensing stuff and legal stuff is not my strong suit).

    Hope this solution will in the meantime help other MySensors users using an ESP32 and also have signing enabled.

    AnticimexA tekkaT 2 Replies Last reply
    2
    • T Technovation

      MySensors Version: 2.3.2 (and prior versions)
      Hardware: ESP32

      Summary of Issue: ESP32 in combination with signing enabled will result in signing failure after fixed number of messages (signing events).

      Detailed description:
      I was performing some benchmark tests with different boards in combination with MY_SECURITY_SIMPLE_PASSWD enabled to analyse the impact on message delays (responsiveness). During these tests with an ESP32 (esp32doit-devkit-v1)
      I experienced that the first set of messages were going all OK, but after a while I stopped receiving messages at the controller.

      Diving deeper into the problem I found:

      • The ESP32 was at fault - resetting the device was sufficient to get things running again (for a while)
      • The problem occurs for both ESP32 configured as Gateway or Node
      • It fails repeatably after the same number of messages after a restart of the ESP32 (and the number of successful messages is sketch dependent - e.g. after 520 messages for my GW sketch and 725 messages for my test node).

      Solution:
      quite some steps of debugging later I found that the signing was failing and the root cause appeared to be a memory leak at:

      MyCryptoESP32.cpp in the SHA256 and the SHA256HMAC functions, which perform a
      mbedtls_md_init(&ctx);, but no call to mbedtls_md_free(&ctx); is present to clear the internal structure created at the end of the function.
      After adding mbedtls_md_free(&ctx); at the end of both SHA256 and SHA256HMAC functions the bug appears to be solved (I stopped testing after 133.000 successful messages :grin: ).

      Another point I noticed in my debugging quest is that I also think I spotted a small "typo" in MySigning.cpp in the signerInternalProcessNonceRequest function.
      In the debug message it reports the SGN:NCE:XMT,TO=xxx, where for xxx now the msg.getSender() is being used, but I suppose that should be msg.getDestination(), i.e. the location (= target Node) TO which the nonce is send.

      I initially wanted to try and make (my first) pull request with this fix, but got stranded at the CLA agreement for now (I don't know if my employer will agree to all the terms in the agreement on the patent licensing stuff and legal stuff is not my strong suit).

      Hope this solution will in the meantime help other MySensors users using an ESP32 and also have signing enabled.

      AnticimexA Offline
      AnticimexA Offline
      Anticimex
      Contest Winner
      wrote on last edited by
      #2

      @Technovation good find. I am not familiar with the esp32 implementation of signing though. Not sure who has implemented it as using a TLS API is not anything I have been involved with. But as it is in git, hit blame will probably lead you to which developer to approach :)

      Do you feel secure today? No? Start requiring some signatures and feel better tomorrow ;)

      1 Reply Last reply
      0
      • T Technovation

        MySensors Version: 2.3.2 (and prior versions)
        Hardware: ESP32

        Summary of Issue: ESP32 in combination with signing enabled will result in signing failure after fixed number of messages (signing events).

        Detailed description:
        I was performing some benchmark tests with different boards in combination with MY_SECURITY_SIMPLE_PASSWD enabled to analyse the impact on message delays (responsiveness). During these tests with an ESP32 (esp32doit-devkit-v1)
        I experienced that the first set of messages were going all OK, but after a while I stopped receiving messages at the controller.

        Diving deeper into the problem I found:

        • The ESP32 was at fault - resetting the device was sufficient to get things running again (for a while)
        • The problem occurs for both ESP32 configured as Gateway or Node
        • It fails repeatably after the same number of messages after a restart of the ESP32 (and the number of successful messages is sketch dependent - e.g. after 520 messages for my GW sketch and 725 messages for my test node).

        Solution:
        quite some steps of debugging later I found that the signing was failing and the root cause appeared to be a memory leak at:

        MyCryptoESP32.cpp in the SHA256 and the SHA256HMAC functions, which perform a
        mbedtls_md_init(&ctx);, but no call to mbedtls_md_free(&ctx); is present to clear the internal structure created at the end of the function.
        After adding mbedtls_md_free(&ctx); at the end of both SHA256 and SHA256HMAC functions the bug appears to be solved (I stopped testing after 133.000 successful messages :grin: ).

        Another point I noticed in my debugging quest is that I also think I spotted a small "typo" in MySigning.cpp in the signerInternalProcessNonceRequest function.
        In the debug message it reports the SGN:NCE:XMT,TO=xxx, where for xxx now the msg.getSender() is being used, but I suppose that should be msg.getDestination(), i.e. the location (= target Node) TO which the nonce is send.

        I initially wanted to try and make (my first) pull request with this fix, but got stranded at the CLA agreement for now (I don't know if my employer will agree to all the terms in the agreement on the patent licensing stuff and legal stuff is not my strong suit).

        Hope this solution will in the meantime help other MySensors users using an ESP32 and also have signing enabled.

        tekkaT Offline
        tekkaT Offline
        tekka
        Admin
        wrote on last edited by
        #3

        @Technovation It take the blame :)
        Thanks for reporting, PR submitted.

        (The debug message is correct; msg contains the incoming nonce request => the sender is the recipient of the nonce response)

        https://github.com/mysensors/MySensors/pull/1402

        T 1 Reply Last reply
        3
        • tekkaT tekka

          @Technovation It take the blame :)
          Thanks for reporting, PR submitted.

          (The debug message is correct; msg contains the incoming nonce request => the sender is the recipient of the nonce response)

          https://github.com/mysensors/MySensors/pull/1402

          T Offline
          T Offline
          Technovation
          wrote on last edited by
          #4

          @tekka thanks for submitting the PR.
          No blaming needed :slightly_smiling_face: , just happy that there are people like you that contribute to this nice project.

          1 Reply Last reply
          2
          • Elin AngelowE Offline
            Elin AngelowE Offline
            Elin Angelow
            wrote on last edited by
            #5

            do you think this is similar issue: https://forum.mysensors.org/topic/11861/gateway-fails-with-tsf-msg-sign-verify-fail-after-period-of-time ?

            1 Reply Last reply
            0
            • Elin AngelowE Offline
              Elin AngelowE Offline
              Elin Angelow
              wrote on last edited by
              #6

              actually it is :) thanks a lot :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              11

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular