33194 Commits

Author SHA1 Message Date
Ben Taylor
98b1bf9f2e fix asserts in old chachapoly_update_too_long_preserves_state function
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit 57ac277339e9e9684caf1e8a3bad20c57678ea83)
2026-06-11 14:10:35 +01:00
Ben Taylor
08accf7b92 Fix code style
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit ef055ea1bbfd17de9eeae11c5f90101361fb02df)
2026-06-11 14:10:21 +01:00
Ben Taylor
8b7fca9ede Add improvement to chacha20 tests
Co-authored-by: minosgalanakis <30719586+minosgalanakis@users.noreply.github.com>
Signed-off-by: Ben Taylor <32939606+bjwtaylor@users.noreply.github.com>
(cherry picked from commit 9d6a54795c96f7f0d7dfc230071dc16c5f47f94a)
2026-06-11 14:10:14 +01:00
Manuel Pégourié-Gonnard
9b3d8dc174 rsa: fix constant-time test for decompose_ret()
We were passing input, while only combined_ret is marked as secret...

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-11 12:26:16 +02:00
Manuel Pégourié-Gonnard
29108ed8ce pk: test buffer too small for RSA-opaque + RSA-alt
A previous commit added tests "normal" PK RSA contexts, but missed
opaque RSA keys and RSA_ALT keys.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-11 11:52:18 +02:00
Manuel Pégourié-Gonnard
9516cc4e70 psa: test buffer too small for RSA decrypt
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-11 11:30:45 +02:00
Ben Taylor
f1c9f7fb25 Add reported by and CVE placeholder
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit ab2a7d5a3472f39190344f754e6cee5039fcba50)
2026-06-10 14:35:58 +01:00
Ben Taylor
38a111dd98 Correct style of ChangeLog
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit 0501e447cc19ed06b69daea5e17585e1294030cd)
2026-06-10 14:35:58 +01:00
Ben Taylor
dafd83e310 Improve ChangeLog
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit c058818451833a748da112e3b8129fd299480ceb)
2026-06-10 14:35:58 +01:00
Ben Taylor
7f945f96e8 Add ChangeLog
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit e71e49e634ba49b2b630f268bc8f0dd392751ec3)
2026-06-10 14:35:58 +01:00
Ben Taylor
ec1641e6a0 Add in tests for ECDHE-PSK integer overflow
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit c567299ee6bade9547a97d3ad1dcd5f3bd98ea6f)
2026-06-10 14:35:58 +01:00
Ben Taylor
f9835c081f Added fix for Integer overflow using a large ECDHE Identity
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit baf449db7e31f031ed5def0fecf417122f72d3ee)
2026-06-10 14:34:37 +01:00
Ronald Cron
02edd2b8c2
Merge pull request #1609 from minosgalanakis/security/mlfbyt4c_tls13_policy_bypass_3.6
Backport 3.6: TLS1.3 client HRR policy bypass[ARM-MLFBYT4C]
2026-06-10 13:03:45 +02:00
Manuel Pégourié-Gonnard
d73eec656c psa: test buffer sized just for actual plaintext
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-10 09:57:20 +02:00
Minos Galanakis
8c458b8cca test_suite_ssl: Updated reject_hrr_selecting_unoffered_group dependencies
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-06-08 15:54:41 +01:00
Manuel Pégourié-Gonnard
4813b0c093 pk: fix builds without PKCS#1 v1.5
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 12:00:02 +02:00
Manuel Pégourié-Gonnard
c76cfd536e pk: also fix RSA-opaque v1.5 decrypt side channels
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:56:59 +02:00
Manuel Pégourié-Gonnard
88d55b8140 Add ChangeLog for the latest RSA padding issues
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Manuel Pégourié-Gonnard
31ac657745 rsa: move CT tests to .constant_time.data
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Manuel Pégourié-Gonnard
7e51c31aef rsa/psa: tune doc about RSA v1.5 decrypt usage
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Gilles Peskine
fe47e9ed89 Define and use mbedtls_rsa_decrypt_decompose_ret()
Use a more structured way of isolating and translating sensitive error codes
from RSA PKCS#1v1.5 decryption.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Gilles Peskine
a818c0a8dd Changelog entry for badmac_seen_or_in_hsfraglen confusion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 21:59:07 +02:00
Ronald Cron
b513676bed
Merge pull request #10772 from mpg/security-link-3.6
[3.6] Update broken link
2026-06-05 16:47:25 +00:00
Minos Galanakis
c3f90ec54d test_suite_ssl: use 3.6 endpoint helper signatures in HRR test
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-06-05 15:16:19 +01:00
Gilles Peskine
24c2875cb0 Fix confusion between ssl->badmac_seen and ssl->in_hsfraglen
Since Mbed TLS 3.6.3, the field `badmac_seen_or_in_hsfraglen` in the
`mbedtls_ssl_context` structure has a dual purpose: it is the new name of
`badmac_seen` for DTLS, and it has a new meaning `in_hsfraglen` for TLS.
This was done to add support for handshake message fragmentation in TLS
while preserving the library ABI.

There was a bug in some places in the code, which reads the dual-purpose
field in the wrong protocol. Specifically:

* `mbedtls_ssl_prepare_handshake_record()` (beginning): mistakenly reads
  `badmac_seen_or_in_hsfraglen` in DTLS to mean `in_hsfraglen`. (DTLS
  handshake defragmentation does not use `in_hsfraglen`.) As a
  consequence, in DTLS, after receiving a record with a bad MAC, the field
  `ssl->in_hslen` was not correctly updated, which causes problems further
  in handshake message processing.
* `mbedtls_ssl_prepare_handshake_record()` (end): correctly updates
  `badmac_seen_or_in_hsfraglen` in TLS with the `in_hsfraglen` meaning.
* `ssl_consume_current_message()`: incorrectly read
  `badmac_seen_or_in_hsfraglen` in DTLS to mean `in_hsfraglen`, and thus
  stops processing messages after receiving a record with a bad MAC.
* `ssl_get_next_record()`: accesses `badmac_seen_or_in_hsfraglen` to mean
  `badmac_seen` in DTLS. No bug here.
* `mbedtls_ssl_handle_message_type()`: reads `badmac_seen_or_in_hsfraglen`
   to mean `in_hsfraglen` in TLS. No bug here.
* `mbedtls_ssl_session_reset_msg_layer()`: both fields need to be reset
  when not partial, and a partial reset only applies to DTLS where we do
  want to preserve `badmac_seen` in a partial reset. No bug here.
* `mbedtls_ssl_context_save()`, `mbedtls_ssl_context_load()`: saving
  `badmac_seen` in DTLS is desired and done. Saving `in_hsfraglen` in TLS
  is harmless.

To fix this, in `ssl_msg.c`, always access the dual-purpose field
`badmac_seen_or_in_hsfraglen` through getters and setters that are specific
to one purpose and that check that the purpose matches the protocol.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
397db25dc3 Add tests demonstrating badmac_seen_or_in_hsfraglen confusion on the server
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
305bab2bbc Add renegotiate=2 option to ssl_client2
In `ssl_client2`, the existing option `renegotiate=1` causes the client to
initiate renegotiation immediately after the initial handshake. Add a
variant `renegotiate=2` that initiates renegotiation after one data exchange.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
ee9ce31e96 Add tests demonstrating badmac_seen_or_in_hsfraglen confusion on the client
After a message with a bad MAC (invalid application data record), try to
renegotiate:

* Test cases where renegotiation (nominal or delayed) is rejected.
  Nothing bad happens.
* A test where renegotiation is misparsed and rejected.
  The subsequent parsing fails.
* A test where the renegotiation request is delayed.
  This causes a heap buffer overflow in `ssl_buffer_message()`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
9124556b6d Check "refusing renegotiation" log in more renegotiation tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
0fb05d3520 Add badmac_limit option to ssl_client2
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
a9fa52a025 Add one-shot bad AD options to udp_proxy
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
e8d780f5af Add udp_proxy options to delay an encrypted handshake message
This can be used to simulate data messages received in the wrong epoch, or
to cause a handshake message to be buffered.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
929ce501bd Test DTLS renegotiation when badmac_seen_or_in_hsfraglen != 0
Non-regression test for a bug introduced with TLS handshake defragmentation
support in Mbed TLS 3.6.2, whereby the confusion between the `badmac_seen`
meaning and the `in_hsfraglen` meaning of `ssl->badmac_seen_or_in_hsfraglen`
causes renegotiation to be processed incorrectly after receiving a message
with a bad MAC.

This bug will be fixed in a subsequent commit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
ba656e8f9b Add some hooks in mbedtls_test_ssl_perform_handshake()
Let test code customize the kitchen sink function
`mbedtls_test_ssl_perform_handshake()` at a few points.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Gilles Peskine
2aa80688d9 Add a missing dependency
Needed by a test certificate.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 15:40:28 +02:00
Manuel Pégourié-Gonnard
70d619741b Update broken link
I believe the existing link was to the TF wiki which has been retired
for some time now.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-05 12:28:55 +02:00
Ronald Cron
d774a25bfe Remove unnecessary dependency
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-05 12:03:16 +02:00
Gilles Peskine
1aaec34173 Add CVE-ID
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:28 +02:00
Gilles Peskine
8c398012dd Add attribution for the second bug
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:28 +02:00
Gilles Peskine
8e07717105 basicConstraints with leading INTEGER field: document the behavior change
Announce the security fix together with the overflow fix, since the two bugs
are pretty much indistinguishable from a black-box perspective, despite
being due to independent problems in the code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:27 +02:00
Gilles Peskine
f67b8e5bde Stop accepting basicConstraints with only pathLenConstraint
In an X.509 certificate, a basicConstraints extension where the cA
field (BOOLEAN) is omitted but the pathLenConstraint field (INTEGER )is
present is syntactically valid, but RFC 5280 states that CAs MUST NOT emit
such a certificate.

Historically, since XySSL 0.9 in 2008, if a basicConstraints extension
started with an INTEGER field, we interpreted that field as a cA value. This
was a deliberate change:

> Fixed x509_get_ext() to accept some rare certificates (like
> www.openssl.org:443) which have an INTEGER instead of a BOOLEAN for
> Extension::BasicConstraints::cA.

However, 18 years later, this does not seem to be relevant, and the details
seem to have been lost. Furthermore, major implementations follow RFC 5280
and interpret `SEQUENCE { INTEGER n }` with cA being set to its default
value (FALSE) and pathLenConstraint set to `n`. This means that such a
certificate with n != 0 would be interpreted as a CA certificate in Mbed TLS
but as a leaf certificate elsewhere, which is dangerous.

Since CAs are not supposed to emit such certificates, stop accepting them
altogether.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:27 +02:00
Gilles Peskine
4fb9c9e439 basicConstraints pathLenConstraint tests: use standard cA type
In test cases for pathLenConstraint parsing in a basicConstraints extension
of an X.509 certificate, use the standard type for the leading cA field,
namely BOOLEAN. The test data was encoding that field as INTEGER, which was
accepted as a deviation from the standard since XySSL 0.9.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:27 +02:00
Gilles Peskine
80807b3af8 Remove unreachable CSR extensionRequest check
It is now unreachable because:

- end_set == end_attr_data is enforced at library/x509_csr.c:236.
- end_exts == end_set is enforced at library/x509_csr.c:248.
- x509_csr_parse_extensions() only returns success if *p == end_exts, enforced
  at library/x509_csr.c:188.

So after a successful x509_csr_parse_extensions() call, *p == end_exts ==
end_set == end_attr_data. The condition at line 257 cannot be true.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:23 +02:00
Gilles Peskine
102d53ea9e Tighten CSR extensionRequest bounds
Don't allow parts of a compound (SEQUENCE or SET) to go beyond the
containing compound.

The inline CSR regression test is derived from the existing "X509 CSR
ASN.1 (OK)" DER test vector. In the extensionRequest attribute, the original
well-formed fragment is:

    a029 3027 06092a864886f70d01090e 311a 3018 ...

where 31 1a is the SET containing the Extensions sequence and 30 18 is the
contained Extensions sequence. The malformed test changes only the SET
length byte, from 1a to 19:

    a029 3027 06092a864886f70d01090e 3119 3018 ...

The attribute SEQUENCE length and the inner Extensions sequence length are
left unchanged. This makes the SET one byte too short for its containing
attribute, so the parser must reject it with
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH instead of parsing the trailing byte as
data outside the SET.

There is no known security impact, just some risk reduction.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:33:16 +02:00
Ben Taylor
723cbadb53 Add ChangeLog
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-05 10:20:36 +01:00
Ben Taylor
e3be807e5c Add fix for OOB key exchange error
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-05 10:18:42 +01:00
Ben Taylor
a6023aef67 update code docs
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-03 11:10:36 +01:00
Ben Taylor
2ddd6a2f25 Improve comments and guards
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-02 13:50:32 +01:00
Manuel Pégourié-Gonnard
ea0a2c6d03 rsa/psa/pk: warn more against PKCS#1 v1.5 decrypt
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 11:10:06 +02:00
Manuel Pégourié-Gonnard
54682ec425 rsa: add CF testing for PKCS#1 v1.5 decode
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 11:10:06 +02:00