From 10c0f770ce5388234b4f5d9ff8ab910804e27219 Mon Sep 17 00:00:00 2001 From: oberon-sk Date: Mon, 13 Feb 2023 13:42:02 +0100 Subject: [PATCH 1/2] asymmetric_encrypt: check output length only if return code is PSA_SUCCESS. Signed-off-by: Stephan Koch --- tests/suites/test_suite_psa_crypto.function | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 20e43c6ac7..4304811ae5 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -7853,7 +7853,9 @@ void asymmetric_encrypt(int key_type_arg, output, output_size, &output_length); TEST_EQUAL(actual_status, expected_status); - TEST_EQUAL(output_length, expected_output_length); + if (actual_status == PSA_SUCCESS) { + TEST_EQUAL(output_length, expected_output_length); + } /* If the label is empty, the test framework puts a non-null pointer * in label->x. Test that a null pointer works as well. */ @@ -7868,7 +7870,9 @@ void asymmetric_encrypt(int key_type_arg, output, output_size, &output_length); TEST_EQUAL(actual_status, expected_status); - TEST_EQUAL(output_length, expected_output_length); + if (actual_status == PSA_SUCCESS) { + TEST_EQUAL(output_length, expected_output_length); + } } exit: From 5819d2c14156cf155a2247ac3fc074d48ab604fe Mon Sep 17 00:00:00 2001 From: Stephan Koch Date: Wed, 22 Feb 2023 13:39:21 +0100 Subject: [PATCH 2/2] Feedback from Arm: guarantee that output_length <= output_size even on error, to reduce the risk that a missing error check escalates into a buffer overflow in the application code Signed-off-by: Stephan Koch --- tests/suites/test_suite_psa_crypto.function | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 4304811ae5..8f0ea253c6 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -7855,6 +7855,8 @@ void asymmetric_encrypt(int key_type_arg, TEST_EQUAL(actual_status, expected_status); if (actual_status == PSA_SUCCESS) { TEST_EQUAL(output_length, expected_output_length); + } else { + TEST_LE_U(output_length, output_size); } /* If the label is empty, the test framework puts a non-null pointer @@ -7872,6 +7874,8 @@ void asymmetric_encrypt(int key_type_arg, TEST_EQUAL(actual_status, expected_status); if (actual_status == PSA_SUCCESS) { TEST_EQUAL(output_length, expected_output_length); + } else { + TEST_LE_U(output_length, output_size); } }