28618 Commits

Author SHA1 Message Date
David Horstmann
c09f36dd1b Invert note about buffer overlap support
When MBEDTLS_PSA_COPY_CALLER_BUFFERS is disabled, it causes overlap to
not be supported.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 10:57:43 +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
d20ffaf06f Remove accidental addition of MBEDTLS_TEST_HOOKS
Remove MBEDTLS_TEST_HOOKS from the default config, to which it was
erroneously added.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-15 19:05:40 +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
62a56d966d Tweak the behaviour of copy handling macros
Specifically:
* Move the creation of the pointer to the copied buffer into the
  DECLARE() macro, to solve warnings about potentially skipping
  initialization.
* Reorder the arguments of the FREE() macro - having a different order
  made it confusing, so keep the order the same throughout.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 18:16:02 +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
0d405d8bb9 Add note about support for buffer overlap
Note that enabling MBEDTLS_PSA_COPY_CALLER_BUFFERS allows full buffer
overlap support, whereas without it, overlap support is reduced to that
documented in the function descriptions.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:20:18 +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
36df4b24d4 Redesign local copy handling macros
* Separate initialization from allocation.
* Rewrite description of macros to fit the new interface.
* Use a longer name to store the local copy objects, to reduce the risk
  of shadowing.
* Use different names for the original and the copy. Append the suffix
  '_external' to the original argument and use the previous name
  for the copy.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:09:00 +00:00
David Horstmann
5a945f584e 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-13 14:09:08 +00:00
David Horstmann
d57c0731c9 Remove spaces around token-pasting macro operator
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-13 14:03:40 +00:00
David Horstmann
bf4ec79085 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-11 17:58:56 +00:00
David Horstmann
3e72db4f51 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-11 17:58:56 +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
00d7a04b82 Add more information to comment on test hooks
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
d596862418 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-11 17:58:56 +00:00
David Horstmann
513101b00f 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-11 17:58:56 +00:00
David Horstmann
e9a88ab0d5 Use macros to manage buffer copies
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
c6977b4899 Copy input and output in psa_cipher_encrypt()
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
David Horstmann
372b8bb6c5 Add memory poisoning hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
dbbfdabfd8
Merge pull request #1121 from gilles-peskine-arm/psa-buffers-test-poison
Memory poisoning function for Asan
2023-12-11 17:56:13 +00:00
Janos Follath
f7f88d6443 Fix style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-12-08 08:41:08 +00:00
Janos Follath
8209ff335e Make local function static
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-12-08 08:41:08 +00:00
Janos Follath
aa5cc7b930 Add Changelog for the Marvin attack fix
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-12-08 08:41:08 +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
6f8ca29ce4 Use the existing definition of __func__
Now that library is in the include path when compiling metatest.c, don't
duplicate the definition of __func__ from library/common.h.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:42:43 +01:00
Gilles Peskine
895ebc30f0 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 19:42:36 +01:00
Gilles Peskine
ef0f01fee6 Memory poisoning: meta-test writes as well as reads
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:42:36 +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
e0acf8787d 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 19:22:03 +01:00
Gilles Peskine
f5dd00288e Fix MSVC build failure
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +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
Dave Rodgman
fb96d800ab
Merge pull request #8569 from yuhaoth/pr/fix-warning-on-arm64-gcc-5.4
fix build warning with arm64 gcc 5.4
2023-11-29 11:52:18 +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