Skip to content

Upgrade mbedtls to v3.6.6#20

Merged
jviotti merged 1 commit intomainfrom
mbedtls-3-6-6
Mar 31, 2026
Merged

Upgrade mbedtls to v3.6.6#20
jviotti merged 1 commit intomainfrom
mbedtls-3-6-6

Conversation

@jviotti
Copy link
Copy Markdown
Member

@jviotti jviotti commented Mar 31, 2026

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 55 files

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Mar 31, 2026

🤖 Augment PR Summary

Summary: Upgrades the vendored Mbed TLS dependency from v3.6.5 to v3.6.6 and updates the build integration accordingly.

Changes:

  • Bumps the Mbed TLS tag in DEPENDENCIES and updates version macros in build_info.h.
  • Updates CMake discovery to include the new psa_crypto_random.c compilation unit.
  • Adds a dedicated PSA RNG implementation (psa_crypto_random.*) with fork protection and new APIs for reseed/deplete/prediction-resistance.
  • Introduces additional input/state validation in crypto paths (e.g., CCM finish checks, FFDH peer public key validation).
  • Adjusts PK/PSA key export/import code to use computed buffer sizing and heap allocation in more cases.
  • Refines DTLS/TLS handshake message buffering and ClientHello handling (including better sequencing and debug output).
  • Includes assorted portability and platform-entropy updates (e.g., configurable /dev/random path handling).

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

key_buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE(old_type, old_bits);
key_buffer = mbedtls_calloc(1, key_buffer_size);
if (key_buffer == NULL) {
return MBEDTLS_ERR_PK_ALLOC_FAILED;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor/mbedtls/library/pk.c:632: export_import_into_psa() returns MBEDTLS_ERR_PK_ALLOC_FAILED even though the function return type is psa_status_t, which mixes error-code domains and can confuse the PSA_PK_TO_MBEDTLS_ERR() mapping at the call site. Consider returning an appropriate PSA status for allocation failure so callers handle it consistently.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

/* mbedtls_rsa_write_key() uses the same format as PSA export, which
* actually calls it under the hood, so we can use the PSA size macro. */
const size_t buf_size = PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits);
unsigned char *buf = mbedtls_calloc(1, buf_size);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor/mbedtls/library/pk_wrap.c:302: buf from mbedtls_calloc() is used immediately in pointer arithmetic (buf + buf_size) without a NULL check, which will crash on allocation failure. Consider handling OOM here before using buf.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

unsigned char *p = buf + buf_size;
key_len = mbedtls_rsa_write_key(rsa, buf, &p);
if (key_len <= 0) {
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor/mbedtls/library/pk_wrap.c:307: on mbedtls_rsa_write_key() failure this path returns directly and skips cleanup:, so the heap buffer holding private key material is leaked and not zeroized. Consider routing this failure through cleanup: so mbedtls_zeroize_and_free() always runs.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

/* This is a (grand...)child of the original process, but
* we inherited the RNG state from our parent. We must reseed! */
#if defined(MBEDTLS_THREADING_C)
mbedtls_mutex_lock(&mbedtls_threading_psa_rngdata_mutex);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor/mbedtls/library/psa_crypto_random.c:147: the return value of mbedtls_mutex_lock() is ignored, but mbedtls_mutex_unlock() is called unconditionally, which could result in unlocking an unheld mutex and data races if locking fails. Consider checking the lock result and failing with a PSA error if the mutex can’t be acquired.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@jviotti jviotti merged commit 8cbbe57 into main Mar 31, 2026
14 checks passed
@jviotti jviotti deleted the mbedtls-3-6-6 branch March 31, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant