1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-07-06 22:10:34 +08:00

11922 Commits

Author SHA1 Message Date
Ronald Cron
a329f398e4
Merge pull request #10210 from gilles-peskine-arm/nv-seed-only-3.6
3.6 only: Test a build with entropy only from NV seed
2025-07-02 07:50:45 +00:00
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
Manuel Pégourié-Gonnard
01b5d6a5be
Merge pull request #10244 from felixc-arm/gcc-15-remove-wnoerror-3.6
[3.6] Turn Wunterminated-string-initialization back into an error
2025-06-26 07:08:56 +00: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
Gilles Peskine
4cbf802231 Properly initialize SSL endpoint objects
In some cases, we were calling `mbedtls_test_ssl_endpoint_free()` on an
uninitialized `mbedtls_test_ssl_endpoint` object if the test case failed
early, e.g. due to `psa_crypto_init()` failing. This was largely harmless,
but could have caused weird test results in case of failure, and was flagged
by Coverity.

Use a more systematic style for initializing the stack object as soon as
it's declared.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-25 14:07:55 +01:00
Gilles Peskine
ae9a5e86f3 Fix accidentally skipped test assertion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-25 14:07:55 +01:00
Gilles Peskine
20eee55d9d Properly initialize SSL endpoint objects
In some cases, we were calling `mbedtls_test_ssl_endpoint_free()` on an
uninitialized `mbedtls_test_ssl_endpoint` object if the test case failed
early, e.g. due to `psa_crypto_init()` failing. This was largely harmless,
but could have caused weird test results in case of failure, and was flagged
by Coverity.

Use a more systematic style for initializing the stack object as soon as
it's declared.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-24 17:26:35 +02:00
Gilles Peskine
971c02c8f6 Fix accidentally skipped test assertion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-24 17:18:47 +02: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
Felix Conway
ea26c23ac5 Turn Wunterminated-string-initialization back into an error
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-23 14:13:36 +01:00
Ari Weiler-Ofek
ed134de3d1 Fixed the same typo in ssl-opt.sh
Signed-off-by: Ari Weiler-Ofek <ari.weiler-ofek@arm.com>
2025-06-20 15:08:35 +01: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
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
Gilles Peskine
03303d88fb Don't mutate dst_size
This lead to `dst_size` not having the intended value in subsequent code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-11 18:24:26 +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
55d211388a Adjust test case with invalid base64
Now that Base64 validates the number of trailing equals, adjust the PEM test
case that has a Base64 payload with a wrong number of trailing equals, where
`mbedtls_pem_read_buffer()` now returns a different error code. I'm not sure
what the exact intent of the test was, so add a variant with trailing equals
as well.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-10 09:42:03 +02:00
Gilles Peskine
13cc0c2122 mbedtls_base64_decode: test dst=NULL with dlen>0
The documentation explicitly says that `*dst = NULL` **or** `dlen = 0`
triggers tell-me-the-output-length mode.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:08:42 +02:00
Gilles Peskine
e7ed8c4c2f Explain some aspects of the tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:08:40 +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
58a4479ace test_suite_lms.data: Updated comments
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-06 14:35:07 +01:00
Gilles Peskine
361799acbe typo
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-06 14:52:06 +02: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
bd6fb46ff6 Add a build with NV seed as the only entropy source
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-06 10:18:36 +02:00
Gilles Peskine
582b6fbad3 We do support builds where NV seed is the only entropy source
We want to support builds where there are no platform entropy
sources (`MBEDTLS_NO_PLATFORM_ENTROPY` enabled), and no custom entropy
sources (`MBEDTLS_ENTROPY_HARDWARE_ALT` disabled), but
`mbedtls_entropy_init()` sets up a working entropy without needing to add
sources manually with `mbedtls_entropy_add_source()`
(`MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES` disabled) thanks to a nonvolatile seed
file injected outside the library's control (`MBEDTLS_ENTROPY_NV_SEED`
enabled).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-06 10:18:33 +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
Gilles Peskine
683a46e6c1 mbedtls_base64_decode: assert sloppy behavior with bad number of =
Add unit tests covering cases where the number of digits plus equal signs is
not a multiple of 4. These are invalid inputs, but they are currently
accepted as long as the number of equal signs is at most 2.

The tests assert the current behavior, not behavior that is desirable.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Gilles Peskine
715bbf3e0c mbedtls_base64_decode: test the reported output length
Reinforce the unit test for `mbedtls_base64_decode()` with valid inputs to
systematically call the function with a smaller output buffer and with an
empty output buffer. Assert the reported necessary output length in those
cases.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Minos Galanakis
c7beb847c9 test_suite_lms: Added negative test for corrupted Merkle path
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-05 09:23:59 +01:00
Minos Galanakis
b72573853a test_suite_lms: Added a test for importing invalid sized key
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-05 09:23:59 +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
9325883d9f Add test using underflow-causing PEM keyfile
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-04 10:06:17 +01:00
Manuel Pégourié-Gonnard
12df5f3a16 Improve unit tests for mbedtls_asn1_store_named_data
Every time we check found->val.p we should also check found->val.len.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-26 10:55:59 +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
13f86e689e Add tests for bug in mbedtls_x509_string_to_names()
The commented out tests cause crashes (in different ways) until the bug
is fixed; the first two test are passing already and are here mostly to
provide a reference point.

The bug report was using programs/x509/cert_write, but string_to_names()
is what it was really targetting, which is better for automated tests.
The strings used are a minor adapation of those from the report.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-22 13:18:49 +02:00
Gilles Peskine
077f8e6353 Restore standard initializers in _init tests
Partially undo "Use short initializers for multipart operation structures",
only in test functions that specifically aim to test initializers. In these
functions, do try with the short initializers, but alongside the standard
ones.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-22 10:26:06 +02:00
Gilles Peskine
93dd99571b Use short initializers for multipart operation structures
When initializing a multipart or interruptible operation structure, use an
auxiliary function that doesn't initialize union members to all-bits-zero.
Context: on most compilers, initializing a union to `{0}` initializes it to
all bits zero; but on some compilers, the trailing part of members other
than the first is left uninitialized. This way, we can run the tests on any
platform and validate that the code would work correctly on platforms where
union initialization is short.

This commit makes a systematic replacement in `test_suite_psa_crypto.function`
and `test_suite_psa_crypto_driver_wrappers.function`, which gives good
enough coverage.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-22 10:26:06 +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
Gilles Peskine
f4ebf807e6 Test with GCC 15 with sloppy union initialization
This is a non-regression test for
https://github.com/Mbed-TLS/mbedtls/issues/9814

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 18:51:57 +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
f9ac5e7728 Add unit test for new behaviour of string_to_names()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-05 18:25:26 +02:00
Gilles Peskine
15bb8e04bf Improve comments
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-30 16:58:00 +02:00
Gilles Peskine
df065720da Allow gcc-15 to be in $PATH
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-25 18:59:45 +02:00
Gilles Peskine
2eab9fd92a Enable drivers when testing with GCC 15
The goal of testing with GCC 15 is to validate fixes for
https://github.com/Mbed-TLS/mbedtls/issues/9814 . The bug is present in
multiple places, and some of them affect third-party drivers but not our
built-in implementation. (The bug is that driver contexts might not be
zero-initialized, but some of our built-in implementations happen not to
care about this.) Thus, enable the test drivers in the test component that
uses GCC 15, to gain the extra checks performed in the driver wrappers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-25 18:59:42 +02:00
Gilles Peskine
bf90dc9c71 GCC 15: Silence -Wunterminated-string-initialization
This is a new warning in GCC 15 that our code base triggers in many places.
Silence it for the time being.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-25 18:58:33 +02:00