Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PSA crypto partition and tests #8935

Merged
merged 5 commits into from
Dec 6, 2018
Merged

Fix PSA crypto partition and tests #8935

merged 5 commits into from
Dec 6, 2018

Conversation

orenc17
Copy link
Contributor

@orenc17 orenc17 commented Dec 2, 2018

Description

  • Styling
  • Correct error codes on failing connection
  • Add panics where needed
  • correct skip defines
  • Fix psa_spm_init_refence_counter bug

Required by #8745

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

@0xc0170 0xc0170 requested a review from a team December 3, 2018 11:09
@0xc0170
Copy link
Contributor

0xc0170 commented Dec 3, 2018

Travis failure will be fixed on master soon (we will request rebase once done). See #8945

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 3, 2018

Travis failure will be fixed on master soon (we will request rebase once done). See #8945

The fix is on master, if you rebase, it should allow travis to run

@cmonr
Copy link
Contributor

cmonr commented Dec 3, 2018

@orenc17 Please take a look at the astyle test.

@orenc17
Copy link
Contributor Author

orenc17 commented Dec 3, 2018

@cmonr Fixed astyle

@cmonr
Copy link
Contributor

cmonr commented Dec 3, 2018

CI started

@@ -83,31 +84,46 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
#ifndef NO_GREENTEA
GREENTEA_SETUP(60, "default_auto");
#endif

/* fill seed in some data */
for (size_t i = 0; i < MBEDTLS_ENTROPY_MAX_SEED_SIZE + 2; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (size_t i = 0; i < MBEDTLS_ENTROPY_MAX_SEED_SIZE + 2; ++i) {
for (size_t i = 0; i < sizeof(seed); ++i) {

@@ -16,7 +16,7 @@
* limitations under the License.
*/

#if ((!defined(TARGET_PSA) || (!defined(COMPONENT_PSA_SRV_IPC)) && !defined(MBEDTLS_ENTROPY_NV_SEED)))
#if (!defined(TARGET_PSA) || ((!defined(COMPONENT_PSA_SRV_IPC)) && !defined(MBEDTLS_ENTROPY_NV_SEED)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please double check this expression - looks suspicious to me
too many parenthesis here

@@ -1067,7 +1067,7 @@ psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed,

handle = psa_connect(PSA_ENTROPY_ID, MINOR_VER);
if (handle <= 0) {
return (PSA_ERROR_COMMUNICATION_FAILURE);
return (PSA_ERROR_NOT_SUPPORTED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psa_connect may fail due to resource exhaustion - does it really means that mbedtls_psa_inject_entropy is not supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, moved the not_supported logic to the call()

@@ -0,0 +1,1376 @@
// ---------------------------------- Includes ---------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cannot review the changes in this file. It was renamed and modified and now appears as a new file.
can we split rename and modify commits so the changes will be reviewable?

@alzix
Copy link
Contributor

alzix commented Dec 3, 2018

CC @Patater please review

@mbed-ci
Copy link

mbed-ci commented Dec 4, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 1
Build artifacts
Build logs

@alzix
Copy link
Contributor

alzix commented Dec 4, 2018

rebased on master and renamed crypto partition from CRYPTO to CRYPTO_SRV for avoiding file names collision between auto-generated files and partition implementation file. This change will help us to review the proposed changes.

@@ -102,5 +98,13 @@ Specification specification(greentea_test_setup, cases, greentea_test_teardown_h

int main()
{
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
/* inject some a seed for test*/
Copy link
Contributor

@Patater Patater Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only needed if the seed hasn't been injected at the factory yet. Factory tool should do this, not our tests, right?

Our tests should be able to assume the device was manufactured correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then the tests won't work. since there is no prior factory injection for tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are expected to work during OOB - so we must inject entropy in tests.
as a side effects tests executed on a device may destroy/corrupt factory values - but this is true for all the tests. KVStore tests will have same effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The board should have entropy injected before it gets inserted into the box at the factory. Then, OOB should work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tend to think of it as our internal tests. so we need to simulate the injection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing entropy injection itself, yes. For testing everything else, no. Tests should be able to assume a properly manufactured board.

Anyway, nothing to do with this PR. We'll sort this out later.

@@ -16,7 +16,7 @@
* limitations under the License.
*/

#if ((!defined(TARGET_PSA) || (!defined(COMPONENT_PSA_SRV_IPC)) && !defined(MBEDTLS_ENTROPY_NV_SEED)))
#if (!defined(TARGET_PSA) || !defined(COMPONENT_PSA_SRV_IPC))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we want the entropy injection tests to run? I'm not sure these defines are right if we want it to run on both "K64F when MBEDTLS_ENTROPY_NV_SEED is configured" and on a "PSoC 6's NSPE when the PSoC 6's SPE has MBEDTLS_ENTROPY_NV_SEED configured".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Patater ideally the test should run on dual-MCU(PSoC6) or v8-m systems
this is being taken care of by COMPONENT_PSA_SRV_IPC define which the K64F will never have

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want this test to keep working on K64F or other single v7-M targets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed inject needs to run also on k64f

@@ -46,14 +46,14 @@ spm_partition_t g_partitions[3] = {
.irq_mapper = NULL,
},
{
.partition_id = PSA_F_ID,
.partition_id = CRYPTO_SRV_ID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to change PSA_F_ID to CRYPTO_ID everywhere, even in non-crypto tests? Maybe the storage tests should use a storage partition and not a crypto partition?

Do the storage tests need Mbed Crypto? Do they need a Crypto partition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an auto-generated file which represents all the partitons defined in the system
specific for this test crypto and storage are the base partitions while its_reset is the additional user partition

and again this file will be compiled only for the secure side on dual-MCU(PSoC6) or v8-m systems only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so Crypto partition should always be available from the SPE.

@@ -41,6 +41,7 @@
using namespace utest::v1;

uint8_t seed[MBEDTLS_ENTROPY_MAX_SEED_SIZE + 2] = {0};
bool skip_tests = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static maybe

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long as the tests work for K64F and PSoC 6, I'm happy with these changes.

@@ -16,7 +16,7 @@
* limitations under the License.
*/

#if ((!defined(TARGET_PSA)) || (!defined(MBEDTLS_PSA_CRYPTO_C)) || (!defined(MBEDTLS_PSA_CRYPTO_SPM )))
#if ((!defined(TARGET_PSA)) || (!defined(COMPONENT_PSA_SRV_IPC)) || (!defined(MBEDTLS_PSA_CRYPTO_C)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ifdefs prevent K64F from running these tests, don't they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repetitive crypto init call will have a different return code on multi core comparing to a single core.
this test as it is written now can only pass on multi core - thus the ifdefs are correct.
you are welcome to update the test and enable it for single core targets in a separate PR.
This PR is a blocker for #8745 thus i suggest to avoid unnecessary last minute enchantments :) .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I had assumed when we added the tests for K64F that they were passing there. Seems the tests are in worse condition that expected, or the tests used to work and after this PR they break on K64F. So long as this PR isn't the cause of the tests not working on K64F, I'm fine with disabling the tests on K64F like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looked into the old code more. This didn't work on K64F before. So, no regression.


#if ( defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO) )
psa_get(PSA_ENTROPY_INJECT, &msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

Oren Cohen and others added 2 commits December 4, 2018 17:07
* Styling
* Correct error codes on failing connection
* Add panics where needed
* correct skip defines
* Fix psa_spm_init_refence_counter bug
@alzix
Copy link
Contributor

alzix commented Dec 4, 2018

i saw travis failures - rebased on master

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 5, 2018

@orenc17 Please take a look at the TESTS-PSA-CRYPTO_INIT compilations.

I can see the branch was forced push. Did this address failures ? Is this ready for CI now?

@orenc17
Copy link
Contributor Author

orenc17 commented Dec 5, 2018

@cmonr @0xc0170 i'm sorry, i thought i pushed that commit last night

@cmonr
Copy link
Contributor

cmonr commented Dec 5, 2018

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 5, 2018

Test run: FAILED

Summary: 3 of 7 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@cmonr
Copy link
Contributor

cmonr commented Dec 5, 2018

Will restart CI when able. There appears to be a parse error with the CI scripts.

@alekla01
Copy link
Contributor

alekla01 commented Dec 5, 2018

CI restarted

@orenc17
Copy link
Contributor Author

orenc17 commented Dec 5, 2018

@cmonr @alekla01 please restart the CI again to check the new commit please

@cmonr
Copy link
Contributor

cmonr commented Dec 5, 2018

@orenc17 Will so as soon as Travis CI has completed its checks.

@cmonr
Copy link
Contributor

cmonr commented Dec 5, 2018

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 5, 2018

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 4
Build artifacts

@mbed-ci
Copy link

mbed-ci commented Dec 5, 2018

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 5
Build artifacts

Copy link
Contributor

@cmonr cmonr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A question about closing parenthesis, and should be good to merge after.

@@ -47,7 +47,7 @@ void inject_entropy()
}
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
}
#endif
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for commenting on closing #endif statements.

case PSA_IPC_CALL: {
#if (defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two )?

(In the end of the line)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmonr i hope the following graphic helps

#if (defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO))
    |       |                       |           |                      ||
    |       -------------------------           ------------------------|
    |                                                                   |
    ---------------------------------------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That it does. My bad.

( 👍 Nice graphic! )

@cmonr cmonr changed the title Fix PSA crypto partiotion and tests Fix PSA crypto partition and tests Dec 6, 2018
@0xc0170 0xc0170 merged commit 8301325 into ARMmbed:master Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants