18403 Commits

Author SHA1 Message Date
David Horstmann
2b70a66118 Put local output status in scope
This means that a unique name is no longer needed.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
f96ae67a76 Remove spaces around token-pasting macro operator
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
e800aa8d34 Make return statuses unique in FREE_LOCAL_OUTPUT()
Previously the return from psa_crypto_local_output_free() had a fixed
name, which meant that multiple outputs would cause redefinitions of the
same variable.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
1f53213830 Improve FREE_LOCAL_INPUT() and FREE_LOCAL_OUTPUT()
* Set swapped pointers to NULL when the buffers are freed.
* Change example name <buffer> to <input> and <output> to reduce
  confusion.
* Document assumptions of FREE_LOCAL_ macros.
* Add comment on error case in FREE_LOCAL_OUTPUT(), explaining why it's
  okay to mask the existing status code.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
0bfaee301a 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-20 14:49:41 +00:00
David Horstmann
114d82407c Add more information to comment on test hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
3e77e982d5 Add missing license header
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
2b10b3713d Remove unnecessary include directory from CMake
Since psa_crypto.c does not include tests/include/test/memory.h, we do
not need the tests/include include path.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
c0a2c30252 Add MBEDTLS_PSA_COPY_CALLER_BUFFERS config option
This allows us to entirely remove copying code, where the convenience
macros are used for copying.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
34980bd832 Use macros to manage buffer copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
f24151a333 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-20 14:49:41 +00:00
David Horstmann
63f82f7c0c 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-20 14:49:41 +00:00
David Horstmann
d2ad886258 Copy input and output in psa_cipher_encrypt()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
96f4d4c6f3 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-20 14:49:41 +00:00
David Horstmann
96a18f2168 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-20 14:49:41 +00:00
David Horstmann
0760b15d45 Add memory poisoning hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
e369fcb23a Disable check_mbedtls_calloc overallocation under ASan
This test case exercises an integer overflow in calloc. Under Asan, with
a modern Clang, this triggers an Asan complaint. The complaint can be
avoided with ASAN_OPTIONS=allocator_may_return_null=1, but this has to
be set in the environment before the program starts, and could hide
other errors.

Reproduced from a commit in mbedtls#8286

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
95b54f34a0
Merge pull request #1129 from gilles-peskine-arm/psa-buffers-test-poison-2.28
Backport 2.28: Memory poisoning function for Asan
2023-12-11 17:56:23 +00:00
Gilles Peskine
7d68a1954c Protect against compiler optimizations
GCC 5.4 optimized the write after poisoning (the surprising thing is that
11.4 doesn't).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
0c7d3eda0a Memory poisoning: meta-test writes as well as reads
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
014d89b782 Avoid unused variable warnings in some plausible usage
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
5e8740576c 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 20:51:56 +01:00
Gilles Peskine
d751406f8d Port to platforms where printf doesn't have %zu
Reuse the existing abstraction from include/mbedtls/debug.h.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
ac8cd66bda Fix MSVC build failure
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
721a64463a Basic functional test for memory poisoning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
962c5da52a 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 20:51:56 +01:00
Gilles Peskine
071d144a2e 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 20:51:56 +01:00
Gilles Peskine
87270e5337 New files for memory-related test functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 20:51:56 +01:00
Gilles Peskine
242e4efcad Merge remote-tracking branch 'mbedtls-2.28' into mbedtls-2.28-restricted 2023-11-29 19:50:46 +01:00
Gilles Peskine
7655fd2d93
Merge pull request #8570 from yuhaoth/pr/fix-ciphersuite-list-wrong-for-mbedtls-2.28
Backport 2.28: ssl-opt.sh: Fix getting the list of supported ciphersuites.
2023-11-29 11:31:35 +00:00
Ronald Cron
ba77a66475 Align forced ciphersuite with test description
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-11-29 10:15:14 +08:00
Ronald Cron
6f2183f756 ssl-opt.sh: Remove unnecessary symmetric crypto dependencies
Same test cases as in the previous commit.
Remove the redundant symmetric crypto dependency.
The dependency is ensured by the fact that:
1) the test case forces a cipher suite
2) ssl-opt.sh enforces automatically that the
   forced ciphersuite is available.
3) The fact that the forced ciphersuite is
   available implies that the symmetric
   cipher algorithm it uses is available as
   well.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-11-29 10:15:12 +08:00
Ronald Cron
237e3f8e53 ssl-opt.sh: Fix some symmetric crypto dependencies
Fix some dependencies on symmetric crypto that
were not correct in case of driver but not
builtin support. Revealed by "Analyze driver
test_psa_crypto_config_accel_cipher_aead vs reference
test_psa_crypto_config_reference_cipher_aead" in
analyze_outcomes.py.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-11-29 10:13:50 +08:00
Ronald Cron
a8b474f42f ssl-opt.sh: Add a check of the list of supported ciphersuites
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-11-29 10:11:47 +08:00
Ronald Cron
46a660a2c5 ssl-opt.sh: Fix getting the list of supported ciphersuites.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-11-29 10:11:17 +08:00
Dave Rodgman
806c27c5f4
Merge pull request #1126 from davidhorstmann-arm/psa-buffer-copy-fn-2.28
[Backport 2.28] Implement buffer copying functions for PSA crypto
2023-11-24 10:46:31 +00:00
David Horstmann
8e1f0d0d31 Improve description of psa_crypto_input_copy_alloc
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
David Horstmann
0d52c71ccd Use initializers in alloc functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
David Horstmann
45221ffdc4 Add casts to local input / output initializers
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
Dave Rodgman
60dcdd1686
Merge pull request #8558 from gilles-peskine-arm/MBEDTLS_TEST_HAVE_xSAN-2.28
Backport 2.28: Fix test_suite_platform failure with Asan on modern Clang
2023-11-23 14:04:09 +00:00
Paul Elliott
20e76134ea
Merge pull request #8557 from gilles-peskine-arm/metatest-gcc-12-2.28
Backport 2.28: Fix metatest.c with gcc-12 -Wuse-after-free
2023-11-23 11:09:24 +00:00
Gilles Peskine
c3a9bdb2b5 Detect enabled GCC/Clang sanitizers
Occasionally we want tests to take advantage of sanitizers, or work around
them.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-22 18:00:31 +01:00
Gilles Peskine
e9616fdbc9 Fix the build with gcc-12 -Wuse-after-free
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-22 17:37:57 +01:00
David Horstmann
1a76ab1c34 Rename "output_copy" -> "local_output"
This helps to prevent confusion as it avoids overloading the word
"copy" as both an action and an object.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:09:04 +00:00
David Horstmann
81a0d57e36 Rename "input_copy" -> "local_input"
This helps to prevent confusion as it avoids overloading the word
"copy" as both an action and an object.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:09:02 +00:00
David Horstmann
48ffb93d7f De-abbreviate "len" -> "length"
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
232ab25bcd Change psa_crypto_copy_output error code
When we are copying output, it makes sense to return
PSA_ERROR_BUFFER_TOO_SMALL since the buffer we are copying to is a user
output buffer.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
34c434a3ca Add initializers for input / output copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
37e3fc6c76 Remove unnecessary checks for NULL-ness of copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
d79d5e7ed0 Check for len == 0 rather than buffer == NULL
This makes the intention clearer

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00