Commit Graph

13810 Commits

Author SHA1 Message Date
Ronald Cron
707c8c34ec Merge remote-tracking branch 'mbedtls-restricted/mbedtls-3.6-release-sync' into 'mbedtls-restricted/mbedtls-3.6-restricted' 2026-03-23 12:08:25 +01:00
Bence Szépkúti
8530b5e708 Merge pull request #1504 from gilles-peskine-arm/psa-rng-fork-3.6
Backport 3.6: PSA RNG fork protection
2026-03-19 17:26:52 +01:00
Gilles Peskine
f6118b40e1 Merge pull request #1492 from minosgalanakis/bugfix/ccm_finish_boundary_check_3.6
Bugfix/ccm finish boundary check 3.6
2026-03-17 21:57:28 +01:00
Ronald Cron
c1cd21d854 Merge pull request #1510 from yanesca/1445_fix_signature_algorithm_injection-backport
Fix signature algorithm injection [3.6 Backport]
2026-03-17 17:09:51 +01:00
Bence Szépkúti
444d0ac2c1 Merge pull request #10443 from davidhorstmann-arm/verify-result-default-failure-3.6
[Backport 3.6] Hardening: Make `mbedtls_ssl_get_verify_result()` default to failure
2026-03-17 12:14:48 +00:00
Manuel Pégourié-Gonnard
b48ddb3f4e Merge pull request #1485 from gilles-peskine-arm/dev-random-config-3.6
Backport 3.6: Use /dev/random and make it configurable
2026-03-17 10:54:46 +01:00
David Horstmann
0501209507 Move TLS 1.3 verify-result setting for PSK
When we are doing PSK, we'd like to set verify_result to
0 to indicate success. Previously this was done in
mbedtls_ssl_set_hs_psk() but this is inadequate since this function may
be called for early data (where certificate verification happens later
in the handshake).

Instead, set this value after writing / processing the encrypted
extensions on the server / client respectively, so that we know whether
we are doing certificate verification or not for sure. This change is
effective only for TLS 1.3 as TLS 1.2 sets verify_result for PSK in
ssl_parse_certificate_coordinate().

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-16 17:19:30 +00:00
Gilles Peskine
fd0e168fab Extend PSA RNG fork protection to NV-seed-only configurations
In builds with only a nonvolatile seed but no actual entropy source, the
naive protection against fork() by reseeding in the child doesn't work:
every child forked from the same RNG state gets the same RNG state. To make
the child's RNG state unique in that case, use a public but unique
personalization string.

The personalization string includes the time. Use `mbedtls_ms_time()` if
available. Fall back to the classic (but obsolescent) `gettimeofday()`
otherwise.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-16 17:50:06 +01:00
Gilles Peskine
0b93865aed Protect the PSA RNG from duplication on fork
If a process forks with the PSA subsystem active, the PSA RNG state is
duplicated. This led to the parent process and the child process generating
the same sequence of random numbers.

Fix this by forcing a reseed if the value of `getpid()` changes. This is the
same technique used in OpenSSL ≥1.1.1d.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-16 17:50:06 +01:00
Bence Szépkúti
c5f0f738ed Merge pull request #1497 from gilles-peskine-arm/psa-rng-reseed-3.6
Backport 3.6: API to reseed the PSA RNG
2026-03-16 13:53:53 +01:00
Janos Follath
5b5e3ba75b Fix ssl_parse_signature_algorithm guards
In 3.6 we still have RSA key exchange and the existing preprocessor
guards are insufficient. Use the same macro to guard the definition that
guards the call.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
b353e92c2b Improve ssl_parse_signature_algorithm
Simplify and improve error reporting and remove unnecessary
initialisation (the caller is responsible for initialising those
values).

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
1f938bc20f Fix code style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
28886c543e ssl_parse_signature_algorithm: match error codes
The caller is returning MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER if
ssl_parse_signature_algorithm() fails, but
ssl_parse_signature_algorithm() returns
MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE upon failure. There is no good reason
for this mismatch and better to be aligned.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
4d70ce2f13 ssl_parse_signature_algorithm: caller to get bytes
After the recent refactoring ssl_parse_signature_algorithm() sends an
alert on failure, but the caller also sends an alert on failure. Sending
two alerts is at least a protocol violation, and might not leave the SSL
context in a good state.

It is simpler to have the caller read the two bytes, and pass them to
this function.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
e50420a2dd Fix code style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:39:01 +00:00
Janos Follath
fcb70427f8 Reintroduce ssl_parse_signature_algorithm
The logic was easier to follow before 693a47a, which removed the
ssl_parse_signature_algorithm function and introduced the bug being
fixed in this PR.

When validating multiple conditions, it's easier to read, easier to
debug and, as we can see, easier to get right if you validate them
separately.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:38:20 +00:00
Janos Follath
0165a8d763 sig_algs: fix typo in client's sig_algs check
This bug caused the client accepting sig_algs used by the server that
it explicitly wanted to disallow.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:37:49 +00:00
Manuel Pégourié-Gonnard
0d48c34169 Merge pull request #1490 from ronald-cron-arm/tls12-2nd-client-hello-3.6
Backport 3.6: Fix TLS 1.2 client hello after HRR
2026-03-16 10:58:44 +01:00
Manuel Pégourié-Gonnard
2d0aa97f81 Merge pull request #1501 from mpg/restricted-ffdh-peerkey-checks
[Backport 3.6] FFDH peer key checks
2026-03-13 12:44:30 +01:00
Manuel Pégourié-Gonnard
01b04ab723 Merge pull request #1489 from davidhorstmann-arm/fix-psa-ffdh-buffer-overflow-3.6
[Backport 3.6] Fix buffer overflow in FFDH public key export
2026-03-13 09:56:43 +01:00
Manuel Pégourié-Gonnard
e24f1e5c2c Merge pull request #10609 from mpg/pk-psa-large-stack-buffers
[3.6] PK: avoid large stack buffers in "to/from PSA" functions
2026-03-13 08:53:48 +00:00
Minos Galanakis
e8a2499d4e ccm: Fixed a missing error flag assertion.
In ccm_calculate_first_block_if_ready when using ccm
tag_len==0 is invalid. When it fails, it will now also
assert the CCM_STATE__ERROR in the state machine's
context.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-12 11:09:31 +00:00
Minos Galanakis
8b50733a73 ccm: Re-ordered len checks in mbedtls_ccm_finish.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-12 11:09:31 +00:00
Minos Galanakis
e96de33867 psa_core: Added a retval in psa_aead_final_checks()
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-11 10:30:57 +00:00
Minos Galanakis
32caf3bad0 ccm: Fail when calling finish without ccm_starts
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-10 22:04:27 +00:00
Ronald Cron
828e3817ac Merge pull request #10623 from ronald-cron-arm/dtls-client-hello-defragmentation-3.6
Backport 3.6: Add support for (D)TLS 1.2 client hello defragmentation
2026-03-10 14:46:41 +00:00
Manuel Pégourié-Gonnard
199d4d9380 FFDH: fix wrong word in comment
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-10 11:40:14 +01:00
Ronald Cron
7476e4067d Restore seq number check of post-handshake ClientHello msg
The check was wrongly removed by the commit
"ssl_tls12_server.c: Move ClientHello message_seq adjustment".

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 10:15:42 +01:00
David Horstmann
01bcc1f754 Add missing FFDH public key buffer length check
When exporting an FFDH public key we were not properly checking the
length of the output buffer and would write the full length of the key
in all cases. Fix this by checking the size of the output buffer before
we write to it.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 09:05:37 +00:00
Ronald Cron
d6977afbd8 ssl_tls12_server.c: Move back the digest update
Move back the digest update just after
the call to mbedtls_ssl_read_record().
It fits well here as we explain in the
comment associated to the call to
mbedtls_ssl_read_record() that we
update it manually.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 09:47:29 +01:00
Ronald Cron
1222d8cbf4 Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 09:47:28 +01:00
Manuel Pégourié-Gonnard
4704b6b4bd Merge pull request #1488 from davidhorstmann-arm/fix-null-pointer-dereference-3.6
[Backport 3.6] Fix null pointer dereference in `mbedtls_x509_string_to_names()`
2026-03-09 12:42:56 +01:00
Gilles Peskine
8f8b70aff1 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260309 2026-03-08 20:26:08 +01:00
Manuel Pégourié-Gonnard
8eb4fba6fb FFDH: expand comment on peerkey check
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:53 +01:00
Manuel Pégourié-Gonnard
c173dfb035 FFDH: improve sanity checks
- avoid grouping checks, for a better debugging experience (breakpoints)
- use a more logical order, checking the key type first

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:45 +01:00
Manuel Pégourié-Gonnard
7a4e2c67b4 FFDH: reorder checks to satisfy picky test
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:22 +01:00
Manuel Pégourié-Gonnard
10c5db67be FFDH: clean up size check
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:52:19 +01:00
Manuel Pégourié-Gonnard
470ee785ca FFDH: rm useless variable
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:51:47 +01:00
Manuel Pégourié-Gonnard
7d9f1b55fc FFDH: validate peer's key as per RFC 7919
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:44:20 +01:00
Minos Galanakis
de24220853 ccm_finish: Updated to only accept lens set by ccm_set_lengths
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-05 09:10:47 +00:00
Gilles Peskine
a863415205 New API psa_random_set_prediction_resistance()
Let applications configure prediction resistance at runtime.

Prediction resistance is always considered disabled when there is no actual
entropy source, only a nonvolatile seed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
5093f08415 New API psa_random_deplete(): force a reseed on the next RNG query
In some scenarios, application or integration code knows that the random
generator should be reseeded, but the reseed cannot or must not happen
immediately and there is no way to report errors. In such scenarios, users
can call the new function `psa_random_deplete()`, which just marks the DRBG
as needing a reseed.

This change requires DRBG modules to treat `reseed_counter == reseed_interval`
as a condition that requires a reseed. Historically they reseeded when
`reseed_counter > reseed_interval`, but that made it impossible to require
a reseed when `reseed_interval == MAX_INT`. Note that this edge case is not
tested.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
bd57d52490 DRBG: make reseed_counter not be off by 1
Change `reseed_counter` to be the number of requests made since the last
reseed, rather than this number minus 1. Thus, reseed when
`reseed_counter >= reseed_interval` rather than
`reseed_counter > reseed_interval`. The field `reseed_counter` is private so
this is not an API change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
ccfb7357a3 New function psa_random_reseed()
Explicit reseed of the PSA random generator.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
fb6503bf62 Add internal function to reseed PSA RNG
Not applicable to an external RNG.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
4de8b1043a Move PSA internal RNG functions to a new module
Move the PSA internal RNG functions (i.e. the parts of the PSA random
generator that are used when `MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG` is not
enabled) to a separate source file.

`mbedtls_psa_crypto_configure_entropy_sources` stays where it is, at least
for now, because it accesses global data directly and because I have no
immediate reason to move it.

Refactoring only, no behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
685a1ce6f4 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260304 2026-03-04 14:39:06 +01:00
Gilles Peskine
9cd92b207f Support testing baremetal builds without the UNIXLIKE code
When `MBEDTLS_TEST_PLATFORM_IS_NOT_UNIXLIKE` is defined, do not enable
`MBEDTLS_PLATFORM_IS_UNIXLIKE`. This lets us test baremetal builds as such
even if we happen to be building for Linux or other Unix-like platform.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
168461a3a9 Unify the detection of Unix-like platforms
We were using slightly different guards to decide whether to include
`<unistd.h>` in different places. Unify those.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00