1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00
Commit Graph

18895 Commits

Author SHA1 Message Date
d7768235da Update library/timing.c
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
2024-01-18 12:25:18 +01:00
e7bfbc27bf Add underflow check to UNPOISON counter decrement
Make sure that extra UNPOISON calls do not cause the poisoning counter
to underflow and wrap around.

Memory that is unpoisoned multiple times should remain unpoisoned.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 15:37:54 +00:00
1b421b1005 Separate memory poisoning tests from generic ASan
Some platforms may support ASan but be C99-only (no C11 support).
These platforms will support ASan metatests but not memory poisoning,
which requires C11 features.

To allow for this, create a separate platform requirement, "poison",
in metatest.c to distinguish generic ASan metatests from ones that
require suppport for memory poisoning.

In practice our platforms support both, so run "poison" tests in
the same all.sh components where we run "asan" ones.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 15:37:54 +00:00
6de5828288 Change memory poisoning flag to a count
This allows unusually-nested memory poisoning to work correctly, since
it keeps track of whether any buffers are still poisoned, rather than
just disabling poisoning at the first call to the UNPOISON() macro.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 15:37:54 +00:00
265415afa1 Merge pull request #1146 from yanesca/update-Marvin-changelog-backport
Update Marvin fix Changelog entry - BACKPORT
2024-01-16 11:19:27 +01:00
86bbb13779 Update Marvin fix Changelog entry
Upon further consideration we think that a remote attacker close to the
victim might be able to have precise enough timing information to
exploit the side channel as well. Update the Changelog to reflect this.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-16 08:56:42 +00:00
d074a5a147 Only run memory poisoning metatests when poisoning
When we cannot memory poison due to platform constraints, do not attempt
to run memory poisoning metatests (but still run other ASan metatests).

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-12 15:47:49 +00:00
756b4dcfa4 Use thread-local flag to enable memory poisoning
Allow memory poisoning to be enabled and disabled at runtime using a
thread-local flag. This allows poisoning to be disabled whenever a PSA
function is called but not through the test wrappers, removing false
positive use-after-poisons.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-12 15:47:49 +00:00
56fd26cee9 Merge pull request #8640 from bensze01/release_components_2.28
[Backport 2.28] Set OpenSSL/GnuTLS variables when running release components
2024-01-11 15:38:23 +00:00
1296ac8348 Merge pull request #8695 from jwinzig-at-hilscher/mbedtls-2.28
Backport 2.28: Fix bug in mbedtls_x509_set_extension
2024-01-10 16:57:03 +00:00
a836a8499e Fix Issue #8687
Signed-off-by: Jonathan Winzig <jwinzig@hilscher.com>
2024-01-10 13:26:36 +01:00
61f4fc24a9 Add tests for Issue #8687
Signed-off-by: Jonathan Winzig <jwinzig@hilscher.com>
2024-01-10 13:26:12 +01:00
8e72c8f154 Merge pull request #1136 from yanesca/fix-marvin-attack-backport
Fix for the Marvin attack - BACKPORT
2024-01-10 12:16:26 +00:00
ce4a3c25fe Add new internal header to visualc project
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-10 08:54:17 +00:00
05bd9a9455 Merge pull request #8685 from gilles-peskine-arm/asymmetric_key_data-secpr1-2.28
Backport 2.28: Fix incorrect test data for SECP_R1 in automatically generated tests
2024-01-09 11:06:41 +00:00
8b736290ad Fix 'missing prototype' warnings
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-09 09:37:06 +00:00
6f499b7ed4 Align Montgomery init with development
The signature and naming of the Montgomrey initialisation function in
development and in the LTS was different. Align them for easier
readability and maintenance.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-09 09:28:48 +00:00
1bc4348477 Indicate which curves Mbed TLS supports
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:55:24 +01:00
4bc4a2d6a5 Note unusual curve size
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:55:24 +01:00
6bf4dfc8db Fix typo in curve name
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:55:24 +01:00
fafc6cd201 Update generated test data files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:55:24 +01:00
64dcb78e42 Add test data for secp192r1
Same generation methodology as 0cbaf056fa:

```
openssl genpkey -algorithm ec -pkeyopt ec_paramgen_curve:P-192 -text |perl -0777 -pe 's/.*\npriv:([\n 0-9a-f:]*)pub:([\n 0-9a-f:]*).*/"$1","$2"/s or die; y/\n ://d; s/,/,\n              /;'
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:53:54 +01:00
92b90b848a Fix mixup between secp224r1 and secp224k1 in test scripts
secp224k1 is the one with 225-bit private keys.

The consequences of this mistake were:

* We emitted positive test cases for hypothetical SECP_R1_225 and
  SECP_K1_224 curves, which were never executed.
* We emitted useless not-supported test cases for SECP_R1_225 and SECP_K1_224.
* We were missing positive test cases for SECP_R1_224 in automatically
  generated tests.
* We were missing not-supported test cases for SECP_R1_224 and SECP_K1_225.

Thus this didn't cause test failures, but it caused missing test coverage
and some never-executed test cases.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-09 09:53:54 +01:00
f81f191770 Fix parsing of C line comments
Fix // comments stopping on 'n' instead of newlines. Also allow
backslash-newline in // comments.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-08 21:06:47 +01:00
d50f7a7a17 Add Changelog for the Marvin attack fix
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 15:28:38 +00:00
54b2edaa8b Add warning for PKCS 1.5 decryption
Any timing variance dependant on the output of this function enables a
Bleichenbacher attack. It is extremely difficult to use safely.

In the Marvin attack paper
(https://people.redhat.com/~hkario/marvin/marvin-attack-paper.pdf) the
author suggests that implementations of PKCS 1.5 decryption that don't
include a countermeasure should be considered inherently dangerous.

They suggest that all libraries implement the same countermeasure, as
implementing different countermeasures across libraries enables the
Bleichenbacher attack as well.

This is extremely fragile and therefore we don't implement it. The use
of PKCS 1.5 in Mbed TLS implements the countermeasures recommended in
the TLS standard (7.4.7.1 of RFC 5246) and is not vulnerable.

Add a warning to PKCS 1.5 decryption to warn users about this.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 15:19:39 +00:00
24bb226232 Extend blinding to RSA result check
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 15:19:11 +00:00
8b246b3d16 Make RSA unblinding constant flow
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 15:12:38 +00:00
f9cc4763f1 Move some bignum functions to internal header
We will need a couple of low level functions to implement safe
unblinding in RSA.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 14:15:08 +00:00
404160a533 Move calculating RR into a separate function
So far we needed it only locally here, but we will need calculating RR
for safe unblinding in RSA as well.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-08 13:53:33 +00:00
a980aa0894 Disable PSA wrappers psa_collect_statuses builds
`psa_collect_statuses.py` runs `make RECORD_PSA_STATUS_COVERAGE_LOG=1`,
which builds with `RECORD_PSA_STATUS_COVERAGE_LOG`. In this mode, the build
includes wrappers for PSA functions, which conflict with the newly
introduced wrappers that are enabled whenever `MBEDTLS_TEST_HOOKS` is
enabled. In the future, the collect-statuses mechanism should use the new
generic wrapper mechanism. For the time being, keep the old wrappers and
avoid the new wrappers when doing the collect-statuses build.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 21:07:35 +01:00
b3d457ce2f PSA wrappers: don't poison buffers when buffer copying is disabled
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 20:33:29 +01:00
7c7b7d5db3 Add review exception warning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 17:28:59 +01:00
e5ebe5e1f5 Remove the manually written poisoning wrapper
This fixes the build with ASan + MBEDTLS_TEST_HOOKS.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 17:11:54 +01:00
42fa8ea38c Update generated PSA wrappers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:59:28 +01:00
c8b22d0713 Generated PSA wrappers: poison/unpoison buffer parameters
For now, only instrument the one function for which buffer copying has been
implemented, namely `psa_cipher_encrypt`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:58:23 +01:00
50580a51ff Enable generated PSA wrappers
Code in unit tests (`tests/suites/*.function`) and in test support
code (`tests/src/**.c`) will now go through the wrapper functions when they
call a PSA API function and `MBEDTLS_TEST_HOOKS` is enabled.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:47:15 +01:00
b7119c527c Declare the outputs from generate_psa_wrappers.py as generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:47:15 +01:00
1b2aec260e Update generated Visual Studio project
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:47:15 +01:00
d5e5e6dbae Commit generated PSA wrappers
Commit files generated by `tests/scripts/generate_psa_wrappers.py`. As of
this commit, the new code is neither useful (the wrappers just call the
underlying functions) nor used (the wrapper functions are not called from
anywhere). This will change in subsequent commits.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:42:40 +01:00
17a14f1711 Adapt wrapper generators from 3.5 to 2.28
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:41:30 +01:00
8519dc9c7e PSA wrapper generator
The new script `tests/scripts/generate_psa_wrappers.py` generates the
implementation of wrapper functions for PSA API functions, as well as a
header that defines macros that redirect calls to the wrapper functions. By
default, the wrapper functions just call the underlying library function.
With `--log`, the wrapper functions log the arguments and return values.

This commit only introduces the new script. Subsequent commits will
integrate the wrappers in the build.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 16:38:17 +01:00
61a852216e Guard the macro definition
It doesn't make sense to define a macro expanding to a non-existent function.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 14:41:10 +01:00
15d32bb60f C function wrapper generator
The Base class generates trivial wrappers that just call the underlying
function. It is meant as a base class to construct useful wrapper generators.

The Logging class generates wrappers that can log the inputs and outputs to
a function.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 14:39:40 +01:00
cedb112359 Python module to parse function declarations from a header file
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-04 14:39:34 +01:00
ffb18d2012 Merge pull request #8670 from daverodgman/default-compiler-all-2.28
Backport CI perf: Use clang by default in all.sh
2024-01-04 12:58:50 +00:00
0fd07d5e10 Mark test function with MBEDTLS_MAYBE_UNUSED
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-01-04 11:37:35 +00:00
52c294acb4 backport MBEDTLS_MAYBE_UNUSED
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-01-04 11:37:17 +00:00
e42c23569b Don't use full path for setting CC
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-01-04 10:35:35 +00:00
9d2c67f8e2 Use gcc in test_full_deprecated_warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-01-04 10:35:16 +00:00