10295 Commits

Author SHA1 Message Date
Ryan Everett
8d606857da Remove unnecessary dependencies from psa_crypto_helpers.h
The psa_test_wrappers.h inclusion was breaking the examples in programs/
on functions with poisoning added

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-02-02 10:33:09 +00:00
Ryan Everett
4c74c4fe84 Fix line-too-long in script
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-02-02 10:33:09 +00:00
Ryan Everett
84a666daa8 Re-add cipher_encrypt to test wrapper script
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-02-02 10:33:09 +00:00
Ryan Everett
77b91e3930 Generate test wrappers for key management
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-02-02 10:33:09 +00:00
Thomas Daubney
f430f47434 Generate test wrappers
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-01-30 12:25:35 +00:00
David Horstmann
9c5c9c351d
Merge pull request #1141 from davidhorstmann-arm/memory-poisoning-runtime-enable
Enable and disable memory poisoning at runtime
2024-01-24 14:46:43 +00:00
David Horstmann
d3efb92922 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:27:50 +00:00
David Horstmann
9de6edd462 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 14:53:08 +00:00
David Horstmann
fad038c501 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 14:23:20 +00:00
David Horstmann
c2ab398d01 Request C11 in CMake (but only for tests)
Set the C_STANDARD property on the mbedtls_test target to 11.
This requests C11 for the tests only.

If C11 is not supported the build will not fail, since
C_STANDARD_REQUIRED is not set, and memory poisoning will be disabled
by a preprocessor check on __STDC_VERSION__.

Additionally, reintroduce previous C99 enforcement on the rest of the
library.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 14:02:40 +00:00
Gilles Peskine
4411c9c1f8 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-15 19:30:48 +01:00
Gilles Peskine
88385c2f74 PSA wrappers: don't poison buffers when buffer copying is disabled
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-15 19:30:29 +01:00
Gilles Peskine
a1871f318b Add review exception warning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-15 19:30:28 +01:00
Gilles Peskine
8e7960b685 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-15 19:22:15 +01:00
Gilles Peskine
90d14d7fc2 Update generated PSA wrappers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-15 19:21:36 +01:00
Gilles Peskine
4adacac142 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-15 19:20:59 +01:00
Gilles Peskine
2b106dec8b 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-15 19:16:16 +01:00
Gilles Peskine
e00150df4a Declare the outputs from generate_psa_wrappers.py as generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-15 19:16:13 +01:00
Gilles Peskine
6e4332cc24 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.

This is a deviation from our normal practice of generating
configuration-independent platform-independent files as part of the build in
the development branch. The PSA test wrappers will be committed to the
repository for some time for two reasons:

* In the short term, we will review the generated code but not fully review
  the generator script.
* The build scripts cannot yet accommodate a generated header file.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-01-15 19:12:05 +01:00
Gilles Peskine
5294bb347c 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-15 19:03:08 +01:00
David Horstmann
8174478f82 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:13:54 +00:00
David Horstmann
2de5abf284 Only poison memory when buffer copying is enabled
Make sure that we don't enable memory poisoning when
MBEDTLS_PSA_COPY_CALLER_BUFFERS is disabled.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 11:26:40 +00:00
David Horstmann
0f06bde936 Add all.sh coponent to test with copying disabled
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 11:10:16 +00:00
David Horstmann
6d43e6d76a Add missing newline at end of file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-18 15:58:17 +00:00
David Horstmann
83ece2fe49 Add extra MBEDTLS_PSA_CRYPTO_C guard for header
Do not include psa_memory_poisoning_wrappers.h unless
MBEDTLS_PSA_CRYPTO_C is set.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-18 15:34:06 +00:00
David Horstmann
666845322c Improve guards around memory poisoning setup
We should not setup or teardown test hooks when we do not have
MBEDTLS_PSA_CRYPTO_C.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-15 18:35:09 +00:00
David Horstmann
853f9f97eb Add missing newline at end of file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 17:17:20 +00:00
David Horstmann
7de0928fd1 Move wrapper include to psa_crypto_helpers.h
This makes memory poisoning wrappers available to (almost) all tests.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:09:07 +00:00
David Horstmann
b489257a0b Move test hook setup and teardown to helpers.c
Setup and teardown test hooks during full test platform setup.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:09:07 +00:00
David Horstmann
a7cde5d296 Move test hook setup functions into a C file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:09:07 +00:00
David Horstmann
b7a5b6ed35 Add comment explaining the purpose of header
Explain why we have the wrappers in psa_memory_poisoning_wrappers.h

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
bbd44a767f Add missing license header
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
410823730b Remove write check in driver wrappers tests
This check is intended to ensure that we do not write intermediate
results to the shared output buffer. This check will be made obselete
by generic memory-poisoning-based testing for all functions.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
e138dce329 Change to use test-hook-based approach
Since we are applying hooks transparently to all tests, we cannot setup
and teardown test hooks in the tests. Instead we must do this in the
test wrappers which are used to pre-poison and unpoison memory.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
8f35a4f003 Create memory poisoning wrapper for cipher encrypt
Use the preprocessor to wrap psa_cipher_encrypt in a wrapper that
poisons the input and output buffers.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
38e4e9c499 Add explicit UNPOISON calls to memory tests
These are needed to allow them to operate on buffer copies without
triggering ASan use-after-poison detection.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
Gilles Peskine
a7d5662f15 Allow PSA test cases to depend on test conditions
In particular, this allows MBEDTLS_TEST_HOOKS.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:49:24 +01:00
Gilles Peskine
81f8132bd5 Avoid unused variable warnings in some plausible usage
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:42:36 +01:00
Gilles Peskine
abfad78655 Use the existing definition of MBEDTLS_TEST_HAVE_ASAN
A definition now exists in tests/helpers.h, which is a better place.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:41:58 +01:00
Gilles Peskine
479a1944e8 Basic functional test for memory poisoning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00
Gilles Peskine
0bdb6dc079 Fix memory poisoning with Asan on arbitrary byte boundaries
Asan poisons memory with an 8-byte granularity. We want to make sure that
the whole specified region is poisoned (our typical use case is a
heap-allocated object, and we want to poison the whole object, and we don't
care about the bytes after the end of the object and up to the beginning of
the next object). So align the start and end of the region to (un)poison to
an 8-byte boundary.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00
Gilles Peskine
d29cce91d0 Add memory poisoning framework
While an area of memory is poisoned, reading or writing from it triggers a
sanitizer violation.

Implemented for ASan.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00
Gilles Peskine
3fd3d05196 New files for memory-related test functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00
Gilles Peskine
0457559323 Merge remote-tracking branch 'development' into development-restricted 2023-11-29 19:21:19 +01:00
Gilles Peskine
18eab984c7
Merge pull request #8560 from lpy4105/issue/8423/optimize-analyze_outcomes_py
Optimize analyze_outcomes.py
2023-11-29 14:51:41 +00:00
Janos Follath
c6f1637f8c
Merge pull request #8534 from paul-elliott-arm/fix_mutex_abstraction
Make mutex abstraction and tests thread safe
2023-11-29 13:26:23 +00:00
Gilles Peskine
172c0b930f
Merge pull request #8561 from ronald-cron-arm/fix-ciphersuites-list-in-ssl-opt
ssl-opt.sh: Fix getting the list of supported ciphersuites.
2023-11-29 11:31:33 +00:00
Pengyu Lv
5dcfd0c613 Some improvements
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-11-29 18:03:28 +08:00
Manuel Pégourié-Gonnard
6b5cedf51f
Merge pull request #8547 from valeriosetti/issue8483
[G2] Make PSA-AEAD work with cipher-light
2023-11-29 08:53:42 +00:00
Pengyu Lv
550cd6f9b2 Use boolean hit instead of int hits
Also fix a typo in the comments.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-11-29 09:17:59 +08:00