lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #64299] Wrongly identified mbedTLS memory configuratio


From: Hamza Hajeir
Subject: [lwip-devel] [bug #64299] Wrongly identified mbedTLS memory configuration
Date: Mon, 12 Jun 2023 16:15:01 -0400 (EDT)

URL:
  <https://savannah.nongnu.org/bugs/?64299>

                 Summary: Wrongly identified mbedTLS memory configuration
                   Group: lwIP - A Lightweight TCP/IP stack
               Submitter: hamzahajeir
               Submitted: Mon 12 Jun 2023 08:14:59 PM UTC
                Category: apps
                Severity: 3 - Normal
              Item Group: Change Request
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: 2.1.2


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Mon 12 Jun 2023 08:14:59 PM UTC By: Hamza Hajeir <hamzahajeir>
Hi there

Thanks for the great and solid library! 

I've had an issue [1] that forced me to debug deeply last couple of days.

I'm using ALTCP_TLS_MBEDTLS on ESP32, have failed to get a pcb out of calling
altcp_tls_new(), that results in mbedtls fails to allocate memory even if very
large memory was available, printing to the log:


> IDF/components/mbedtls/mbedtls/library/ssl_tls.c:3857: alloc(16717 bytes)
failed
> mbedtls_ssl_setup failed


It starts by the user call [altcp_tls_create_config_server], which creates tls
config first, which in its turn initializes memory by
[altcp_mbedtls_mem_init], which overrides mbedtls calloc/free [2].

In which its implementation [tls_malloc] compares against LWIP defined macro
(MEM_SIZE), which is defaulted to 1600.

Yes, correct that the overriding is protected by the preprocessor
(ALTCP_MBEDTLS_PLATFORM_ALLOC) but it's wrongly defined regarding mbedtls
configuration.

MbedTLS has three states of memory configuration:

- normal `calloc()`/`free()`, which can be easily overriden when
`MBEDTLS_PLATFORM_MEMORY` is defined.

- Platform standard calloc/free, which is the platform's standard calls
(MBEDTLS_PLATFORM_STD_{CALLOC/FREE}), (in ESP32 are mapped to its own
`heap_caps_calloc()`/`heap_caps_free()` (header [3]) (source [4]))

- Platform-defined macros `MBEDTLS_PLATFORM_{CALLOC,FREE}_MACRO`.

Wherein LwIP relies in defining ALTCP_MBEDTLS_PLATFORM_ALLOC by Only the
non-standard platform macros, while it 'should' also consider the standard
definition macros (MBEDTLS_PLATFORM_STD_CALLOC).

So what's proposed is to add a check to the preprocessor at
(altcp_tls/altcp_tls_mbedtls_mem.c) to become:


#if defined(MBEDTLS_PLATFORM_MEMORY) && \
     !defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
    !defined(MBEDTLS_PLATFORM_STD_CALLOC)


Keep in mind that mbedTLS checks for misconfiguration (missing the correlated
free/calloc or mixing std-defined with platform-defined) [5]:


[1] https://github.com/espressif/esp-idf/issues/11647
[2]
https://github.com/lwip-tcpip/lwip/blob/e29870c15e8bf28eac9c811dd236c474f3f2008f/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c#LL167C3-L167C35
[3]
https://github.com/espressif/esp-idf/blob/master/components/mbedtls/port/include/mbedtls/esp_config.h#L125-L127
[4]
https://github.com/espressif/esp-idf/blob/master/components/mbedtls/port/esp_mem.c#L14-L40
[5]
https://github.com/espressif/mbedtls/blob/15b55d406db3918bac88aaf5ef2c6e036d1e0f0e/include/mbedtls/check_config.h#L470-L496








    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?64299>

_______________________________________________
Message sent via Savannah
https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]