Skip to content

Conversation

@yanesca
Copy link
Collaborator

@yanesca yanesca commented Nov 22, 2019

Initialising the return values to an error is best practice and makes the library more robust.

No new error was introduced because we are running out of error codes and we shouldn't be wasting them.

We already had an error code reserved for generic errors. This PR makes it explicit and uses this error code to initialise return values.

Define a new error code MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED for this purpose.

@yanesca yanesca force-pushed the iotcrypt-942-initialise-return-values branch 2 times, most recently from cbb35dc to 82b3173 Compare November 22, 2019 14:26
@yanesca yanesca added needs: preceding PR Requires another PR to be merged first needs: review The pull request is ready for review. This generally means that it has no known issues. labels Nov 22, 2019
@yanesca
Copy link
Collaborator Author

yanesca commented Nov 22, 2019

CI fails because Mbed OS uses Mbed TLS's error.h and should pass once Mbed TLS has been updated.

Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Ok except for the choice of error code.

@gilles-peskine-arm gilles-peskine-arm added needs: work The pull request needs rework before it can be merged. and removed needs: review The pull request is ready for review. This generally means that it has no known issues. labels Nov 22, 2019
One of the error codes was already reserved, this commit just makes it
explicit. The other one is a new error code for initializing return
values in the library: `MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED` should
not be returned by the library. If it is returned, then it is surely a
bug in the library or somebody is tampering with the device.
Initialising the return values to and error is best practice and makes
the library more robust.
@yanesca yanesca force-pushed the iotcrypt-942-initialise-return-values branch from 82b3173 to 24eed8d Compare December 3, 2019 16:08
@yanesca yanesca added needs: review The pull request is ready for review. This generally means that it has no known issues. and removed needs: work The pull request needs rework before it can be merged. labels Dec 4, 2019
@yanesca
Copy link
Collaborator Author

yanesca commented Dec 4, 2019

I have added a new error code for this purpose and simplified the approach as well. The PR is ready for review again.

@gilles-peskine-arm
Copy link
Collaborator

There are many CI failures. I don't think this PR is ready.

@yanesca
Copy link
Collaborator Author

yanesca commented Dec 4, 2019

CI fails because Mbed OS uses Mbed TLS's error.h and should pass once Mbed TLS has been updated.

@yanesca
Copy link
Collaborator Author

yanesca commented Dec 4, 2019

In retrospect I probably should have started with the Mbed TLS PR, but now I would prefer to continue with the review of this one and raise the Mbed TLS counterpart when this is approved. (I would like to do them sequentially to minimise duplicating work during review.)

@gilles-peskine-arm
Copy link
Collaborator

Ok. Reviewing.

Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM

There are a few places where we use int ret = 0; and we could change it to int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;. I found: mbedtls_cipher_finish, block_cipher_df, ctr_drbg_update_internal, mbedtls_ctr_drbg_random_with_add, mbedtls_ctr_drbg_update_seed_file, mbedtls_ecdsa_genkey, mbedtls_ecp_read_key, entropy_update, mbedtls_entropy_update_seed_file, mbedtls_hkdf_expand, mbedtls_hmac_drbg_update_seed_file, mbedtls_nist_kw_wrap, mbedtls_nist_kw_unwrap, mbedtls_rsa_rsassa_pkcs1_v15_verify.

@AndrzejKurek AndrzejKurek self-requested a review December 9, 2019 13:36
* For historical reasons, low-level error codes are divided in even and odd,
* even codes were assigned first, and -1 is reserved for other errors.
*
* Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this information.

* even codes were assigned first, and -1 is reserved for other errors.
*
* Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
* Low-level module errors (0x0001-0x007E, 0x0003-0x007F)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it rather be (even, odd)?

Suggested change
* Low-level module errors (0x0001-0x007E, 0x0003-0x007F)
* Low-level module errors (0x0002-0x007E, 0x0001-0x007F)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, my bad.

@Patater Patater added the needs: work The pull request needs rework before it can be merged. label Dec 11, 2019
@yanesca yanesca removed the needs: work The pull request needs rework before it can be merged. label Dec 12, 2019
@gilles-peskine-arm gilles-peskine-arm removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label Dec 13, 2019
@Patater Patater removed the needs: preceding PR Requires another PR to be merged first label Dec 19, 2019
@Patater Patater merged commit 795c6ba into ARMmbed:development Dec 19, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Feb 3, 2020
Previously in d875285:
* ARMmbed#333: Streamline PSA key type encodings: prepare
* ARMmbed#323: Initialise return values to an error

Previously in dbcb442:
* ARMmbed#291: Test MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
* ARMmbed#334: Fix some pylint warnings

Previously in ceceedb:
* ARMmbed#348: Bump version to Mbed TLS 2.20.0 and crypto SO version to 4
* ARMmbed#354: Fix incrementing pointer instead of value

In this commit:
* ARMmbed#349: Fix minor defects found by Coverity
* ARMmbed#179: Add option to build SHA-512 without SHA-384
* ARMmbed#327: Implement psa_hash_compute and psa_hash_compare
* ARMmbed#330: Streamline PSA key type and curve encodings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants