6354 Commits

Author SHA1 Message Date
David Horstmann
4dc176a430 Add missing newline at end of file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
cb229db971 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-20 14:49:41 +00:00
David Horstmann
ffcc769184 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-20 14:49:41 +00:00
David Horstmann
7cb734370a Add missing newline at end of file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
David Horstmann
9c97fda0ab 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-20 14:49:41 +00:00
David Horstmann
f3c57149d1 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-20 14:49:41 +00:00
David Horstmann
8c2d029661 Move test hook setup functions into a C file
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
3e77e982d5 Add missing license header
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
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
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
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
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
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
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
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
David Horstmann
2d730c015e Compare buffers even for zero-length cases
This enables us to test that lengths are correctly zero when the buffer
pointer is NULL.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
0ee4d18bc6 Use TEST_CALLOC_NONNULL
Check that input/output copying works for zero-length NULL input
buffers.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
e8a92227dc Change data pattern to simpler one
Just use the index modulo 256, as this has a greater stride and is
simpler to use.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
df49355faa Make copy functions static-testable
This allows greater compiler optimisation.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:29 +00:00
David Horstmann
ba65bd79e8 Add output round-trip testcase
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
aca210d4c7 Add input round-trip testcase
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
3bc1316ceb Add testcase for psa_crypto_output_copy_free()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
1acf7afa83 Add testcase for psa_crypto_output_copy_alloc()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
6790a6d36f Add testcase for psa_crypto_input_copy_free()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
89299c476c Add testcase for psa_crypto_input_copy_alloc()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
cbdec9e470 Remove psa_crypto_alloc_and_copy() API
This tied input and output buffers together in
awkward pairs, which made the API more difficult
to use.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
93e08c6db6 Move buffer copy tests into new testsuite
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:56:46 +00:00
David Horstmann
8684ad548f Switch error code to more appropriate value
Since we are internal rather than user-facing,
PSA_ERROR_CORRUPTION_DETECTED makes more sense than
PSA_ERROR_BUFFER_TOO_SMALL. Whilst it really is a buffer that is too
small, this error code is intended to indicate that a user-supplied
buffer is too small, not an internal one.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
89b4caab53 Switch to TEST_CALLOC_NONNULL()
This removes some gubbins related to making sure the buffer is not NULL
that was previously cluttering the test case.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
113f2d46b0 Switch from ret to status as naming convention
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00