1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-07-12 19:18:57 +08:00

13609 Commits

Author SHA1 Message Date
minosgalanakis
1a22f21b74
Merge pull request #1381 from Mbed-TLS/mbedtls-3.6.4-mergeback
Mbedtls 3.6.4 merge-back pr
2025-06-30 22:06:11 +01:00
Minos Galanakis
5b9c7c5204 Revert "Added generated files"
This reverts commit 59e8b3a6b0f11fcbd0ae20355786fafaae49d5d2.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-30 18:33:00 +01:00
Minos Galanakis
59e8b3a6b0 Added generated files
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-25 14:18:23 +01:00
Minos Galanakis
5374262f3b Version bump 3.6.4
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-25 14:07:55 +01:00
Minos Galanakis
f36277558a Merge remote-tracking branch 'restricted/mbedtls-3.6-restricted' into mbedtls-3.6.4rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-23 18:52:17 +01:00
David Horstmann
5e1e5b3e53
Merge pull request #10241 from ariwo17/backport-typo-fixes-3.6
[BACKPORT] Fixed some minor typos in comments.
2025-06-23 16:33:41 +00:00
David Horstmann
54ceaf7a53
Merge pull request #10200 from aslze/mbedtls-3.6
[3.6] Fix build C++ apps with MSVC
2025-06-19 14:25:50 +00:00
Ari Weiler-Ofek
fb2460ae0b Fixed some minor typos in comments.
Signed-off-by: Ari Weiler-Ofek <ari.weiler-ofek@arm.com>
2025-06-19 15:15:30 +01:00
Ronald Cron
7df899211a fix: additional MSVC v142 build issue with tls1.3 configuration enabled.
Signed-off-by: Cesar Cruz <cesar.cruz@philips.com>
Signed-off-by: ccrugoPhilips <cesar.cruz@philips.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-06-18 10:13:54 +02:00
David Horstmann
a84be59757
Merge pull request #1366 from gilles-peskine-arm/base64-decode-clean-3.6
Backport 3.6: mbedtls_base64_decode: fix sloppiness
2025-06-17 14:55:39 +01:00
Gilles Peskine
3c9ad42719
Merge pull request #1367 from gilles-peskine-arm/aesni_has_support-volatile-3.6
Backport 3.6: Fix race condition in mbedtls_aesni_has_support
2025-06-13 23:20:28 +02:00
Gilles Peskine
853cfbdced Add a note about processor memory reordering
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-12 18:30:45 +02:00
Felix Conway
766be1f8f4 Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING
This macro applies __attribute__((nonstring)) when the compiler supports
it

Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-12 11:13:33 +01:00
Gilles Peskine
51dccfb2a6 Improve some explanations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-11 18:47:31 +02:00
Felix Conway
2e1399f1e1 Add __attribute__ ((nonstring)) to remove unterminated-string-initialization warning
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-11 16:04:30 +01:00
Gilles Peskine
a79525239f
Merge pull request #1359 from Mbed-TLS/bugfix_1351_1352_1353_lms_drivers_3.6bp
[3.6 Backport]Bugfix: lms/lmots driver hardening.
2025-06-10 19:08:15 +02:00
Manuel Pégourié-Gonnard
7ed3653c57
Merge pull request #1363 from gilles-peskine-arm/3.6-restricted-merge-20250606
Merge mbedtls-3.6 into mbedtls-3.6-restricted
2025-06-10 11:01:11 +02:00
Manuel Pégourié-Gonnard
cae443405e
Merge pull request #1347 from mpg/fix-asn1-store-named-data-null-deref-3.6
Backport 3.6: Fix asn1 store named data null deref
2025-06-10 09:50:34 +02:00
Gilles Peskine
8c67ac0f7f Fix race condition in mbedtls_aesni_has_support
Fix a race condition in `mbedtls_aes_ni_has_support()` with some compilers.
A compiler could hoist the assignment `done = 1` above the assignment to `c`,
in which case if two threads call `mbedtls_aes_ni_has_support()` at almost
the same time, they could be interleaved as follows:

    Initially: done = 0, c = 0

    thread A                thread B
    if (!done)
      done = 1;                                     # hoisted
                            if (!done)
                                return c & what;    # wrong!
      c = cpuid();
    return c & what

This would lead to thread B using software AES even though AESNI was
available. This is a very minor performance bug. But also, given a very
powerful adversary who can block thread A indefinitely (which may be
possible when attacking an SGX enclave), thread B could use software AES for
a long time, opening the way to a timing side channel attack.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:48:34 +02:00
Gilles Peskine
2b3d6a8f28 mbedtls_base64_decode: insist on correct padding
Correct base64 input (excluding ignored characters such as spaces) consists
of exactly 4*k, 4*k-1 or 4*k-2 digits, followed by 0, 1 or 2 equal signs
respectively.

Previously, any number of trailing equal signs up to 2 was accepted, but if
there fewer than 4*k digits-or-equals, the last partial block was counted in
`*olen` in buffer-too-small mode, but was not output despite returning 0.

Now `mbedtls_base64_decode()` insists on correct padding. This is
backward-compatible since the only plausible useful inputs that used to be
accepted were inputs with 4*k-1 or 4*k-2 digits and no trailing equal signs,
and those led to invalid (truncated) output. Furthermore the function now
always reports the exact output size in buffer-too-small mode.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:01:21 +02:00
Minos Galanakis
df2f0aae81 lms.c: Updated documentation
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-06 14:35:07 +01:00
Gilles Peskine
7df273bb34 Merge remote-tracking branch 'mbedtls-3.6' into mbedtls-3.6-restricted 2025-06-06 10:46:03 +02:00
Gilles Peskine
84999d1a7b Fix mbedtls_base64_decode() accepting invalid inputs with 4n+1 digits
The last digit was ignored.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Minos Galanakis
9b3051fb10 Built-in lms driver: always zeroize output-buffer in create_merkle_leaf_value
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-04 16:23:57 +01:00
Minos Galanakis
ae449bfca5 Built-in lms driver:Check return values of Merkle node creation
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-04 15:54:49 +01:00
Minos Galanakis
caaffc1e7e Built-in lms/lmots driver: Harden public key import against enum truncation
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-04 15:54:46 +01:00
Minos Galanakis
548e2dbf65 Built-in lms driver: Added input guard
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-04 15:20:38 +01:00
David Horstmann
3f82706cb7
Merge pull request #1349 from felixc-arm/pem-integer-underflow-3.6
[3.6] Fix Integer Underflow when Decoding PEM Keys
2025-06-04 14:36:35 +01:00
Felix Conway
6165e71589 Add fix for PEM underflow
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-04 10:06:26 +01:00
Manuel Pégourié-Gonnard
e51bde06da Fix possible UB in mbedtls_asn1_write_raw_buffer()
This is mostly unrelated to other commits in this PR, except for the
fact that one of the added X.509 tests revealed that with UBSan.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-06-03 11:23:19 +02:00
Manuel Pégourié-Gonnard
2df7ab7c0c Fix bug in mbedtls_asn1_store_named_data()
When passed a zero-length val, the function was free-ing the buffer as
the documentation suggests:

 * \param val_len   The minimum length of the data buffer needed.
 *                  If this is 0, do not allocate a buffer for the associated
 *                  data.
 *                  If the OID was already present, enlarge, shrink or free
 *                  the existing buffer to fit \p val_len.

However it kept the previous length, leaving the val structure in the
corresponding item in the output list in an inconsistent state:

    p == NULL but len != 0

As a result, functions that would try using this item in the list
(including the same function!) afterwards would trip an dereference the
NULL pointer.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-26 10:42:14 +02:00
Manuel Pégourié-Gonnard
1e9267c993
Merge pull request #1340 from mpg/fix-string-to-names-uaf-3.6
[3.6] Fix string to names memory management
2025-05-21 14:48:43 +02:00
Deomid rojer Ryabkov
fb5e2e5e46 Mark ssl_tls12_preset_suiteb_sig_algs const
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-05-19 20:48:13 +01:00
Deomid rojer Ryabkov
e3aaf82a77 Mark ssl_tls12_preset_default_sig_algs const
To place in flash and save RAM on targets where this applies.

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-05-19 20:48:08 +01:00
Gilles Peskine
91b29a0bd9 Grammar in comments
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-13 11:53:31 +02:00
Gilles Peskine
0e4907d4f5 Initialize MAC context in internal functions for one-shot MAC
In functions that bypass the API functions and call an internal MAC setup
function directly, make sure to initialize the driver-specific part of the
context. This is a union, and initializing the union to `{0}` only
guarantees that the first member of the union is initialized, not
necessarily the member used by the driver. Most compilers do initialize the
whole union to all-bits-zero, but some don't. With compilers that don't, the
lack of initialization caused failures of the affected operations. This
affected one-shot MAC operations using the built-in implementation.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 18:42:52 +02:00
Gilles Peskine
bbec1c1d25 Initialize MAC context in internal functions for KDF
In functions that bypass the API functions and call the MAC driver wrapper
`psa_driver_wrapper_mac_sign_setup()` directly, make
sure to initialize the driver-specific part of the context. This is a union,
and initializing the union to `{0}` only guarantees that the first member of
the union is initialized, not necessarily the member used by the driver.
Most compilers do initialize the whole union to all-bits-zero, but some
don't. With compilers that don't, the lack of initialization caused failures
of the affected operations. This affected several key derivation operations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 18:42:33 +02:00
Gilles Peskine
a7a480bb81 Initialize driver context in setup functions
In API functions that set up a multipart or interruptible operation, make
sure to initialize the driver-specific part of the context. This is a union,
and initializing the union to `{0}` only guarantees that the first member of
the union is initialized, not necessarily the member used by the driver.
Most compilers do initialize the whole union to all-bits-zero, but some
don't. With compilers that don't, the lack of initialization caused failures
of built-in MAC, interruptible-sign and interruptible-verify. It could also
cause failures for other operations with third-party drivers: we promise
that drivers' setup entry points receive a zero-initialized operation
structure, but this promise was not kept.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 18:41:59 +02:00
Manuel Pégourié-Gonnard
219c3368eb
Merge pull request #1306 from davidhorstmann-arm/pkcs7-padding-side-channel-fix-3.6
[Backport 3.6] Fix side channel in PKCS7 padding
2025-05-06 09:34:40 +02:00
Manuel Pégourié-Gonnard
acdcb7fcd1 Restore behaviour of mbedtls_x509write_set_foo_name()
The documentation doesn't say you can't call these functions more than
once on the same context, and if you do it shouldn't result in a memory
leak. Historically, the call to mbedtls_asn1_free_named_data_list() in
mbedtls_x509_string_to_names() (that was removed in the previous commit)
was ensuring that. Let's restore it where it makes sense. (These are the
only 3 places calling mbedtls_x509_string_to_names() in the library.)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-05 16:49:45 +02:00
Manuel Pégourié-Gonnard
19d2c9165a Fix undocumented free() in x509_string_to_names()
Now programs/x509/cert_write san="DN:CN=#0000;DN:CN=#0000" is no longer
crashing with use-after-free, instead it's now failing cleanly:

 failed
  !  mbedtls_x509_string_to_names returned -0x2800 - X509 - Input invalid

That's better of course but still not great, will be fixed by future
commits.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-05 16:44:18 +02:00
Gilles Peskine
cdb37812e5 Update obsolete section title
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-25 18:48:36 +02:00
Xavier Chapron
afedef5eea Constify cipher_wrap:mbedtls_cipher_base_lookup_table
This structure is initialized during the compilation and there is no
reason it changes.
Making it const allows the compiler to put it in .rodata section instead
of .data one.

Signed-off-by: Xavier Chapron <chapron.xavier@gmail.com>
2025-04-18 09:24:36 +02:00
Max Fillinger
1b0e2e903b Add missing ifdef for mbedtls_ssl_tls13_exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 14:35:24 +02:00
Max Fillinger
40c202461f Add label_len argument to non-PSA tls_prf_generic
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00
Max Fillinger
5122dc6219 Fix mistake in previous comment change
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00
Max Fillinger
7833b18008 Fix HkdfLabel comment
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00
Max Fillinger
529931a34a Allow maximum label length in Hkdf-Expand-Label
Previously, the length of the label was limited to the maximal length
that would be used in the TLS 1.3 key schedule. With the keying material
exporter, labels of up to 249 bytes may be used.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00
Max Fillinger
76bb753054 Fix max. label length in key material exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00
Max Fillinger
97a287953f Document BAD_INPUT_DATA error in key material exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 11:24:50 +02:00