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

Add platform error codes #1993

Merged
merged 5 commits into from
Oct 28, 2018
Merged

Conversation

RonEld
Copy link
Contributor

@RonEld RonEld commented Aug 29, 2018

Description

Add error codes for the platform module, to be used by
the setup \ terminate API, as suggested in ARMmbed/mbed-os#7099 (comment)

Status

READY

Requires Backporting

NO

Add error codes for the platform module, to be used by
the setup \ terminate API.
@RonEld RonEld added enhancement mbed TLS team needs-review Every commit must be reviewed by at least two team members, component-platform Portability layer and build scripts labels Aug 29, 2018
Remove the invalid input for the platform module,
as it's not currently used in the Mbed OS platform setup \
termination code.
@@ -43,6 +43,8 @@
#include "platform_time.h"
#endif

#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware platform function failed. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just say "Hardware failure"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of our HW failure error codes have the suffix of HW_ACCEL_FAILED.
For exampleMBEDTLS_ARIA_HW_ACCEL_FAILED

This is not a HW accelerator, but more of a platform HW failure, so I removed the "ACCEL" part.

Since the error code was already merged to Mbed OS, unless this is a blocker, I prefer to keep the same error code.

Unless your comment was about the error comment, then I'll change

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, my comment was about the error message/comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change, but this error is for the platform function, not a generic hardware failure.

How about " Hardware platform operation failure." ?

Copy link
Contributor

@Patater Patater Sep 7, 2018

Choose a reason for hiding this comment

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

I'd suggest:

#define MBEDTLS_ERR_PLATFORM_HW_FAILED       -0x0080 /**< Hardware failed platform operation. */
``

@@ -80,6 +80,7 @@
* CHACHA20 3 0x0051-0x0055
* POLY1305 3 0x0057-0x005B
* CHACHAPOLY 2 0x0054-0x0056
* PLATFORM 1 0x0080-0x0080
Copy link
Contributor

Choose a reason for hiding this comment

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

Petty - but the alignment is out by one column isn't it?

@@ -43,6 +43,8 @@
#include "platform_time.h"
#endif

#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware platform function failed. */

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really the only error code we want to add?

How about "already in use/busy"? Or "Invalid operation"? I'd suggest out of memory, but I think we already have plans for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not know what are the plans to handle the wide range of error codes that underlying platform/hardware might come across, but my guess is that each platform is most likely to end up returning their specific error codes. So I think its probably OK to just have this very generic error macro and add more as needed or see how we can integrate the platform errors with ours in some other way...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did have an "invalid operation" error code, but since I wasn't using it at the end, I didn't see a point of adding it.
We could think of many error codes to add, as the hw can fal on numerous reasons. I think that if we find ourselves in a need for other error codes, we could add. We already are low in available error values

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, let's add the error codes when we have a need for them (not in this PR).

@andresag01
Copy link
Contributor

There are already two reviews with a couple of minor rework suggestions. I will remove the 'needs review' label and add 'needs rework' to highlight that these should be considered (either by code change or replying to the comments) before further review and approval.

@andresag01 andresag01 added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Sep 12, 2018
1. Rephrase error description.
2. fix alignment of error list.
@RonEld RonEld added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Sep 12, 2018
@RonEld
Copy link
Contributor Author

RonEld commented Sep 12, 2018

@sbutcher-arm @Patater I addressed your comments.
Please review

Patater
Patater previously approved these changes Sep 12, 2018
@@ -43,6 +43,8 @@
#include "platform_time.h"
#endif

#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware platform function failed. */

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, let's add the error codes when we have a need for them (not in this PR).

simonbutcher
simonbutcher previously approved these changes Sep 21, 2018
@simonbutcher simonbutcher added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Sep 21, 2018
@RonEld RonEld mentioned this pull request Oct 4, 2018
4 tasks
@@ -80,6 +80,7 @@
* CHACHA20 3 0x0051-0x0055
* POLY1305 3 0x0057-0x005B
* CHACHAPOLY 2 0x0054-0x0056
* PLATFORM 1 0x0080-0x0080
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The low level error codes are limited up to 0x7f
This causes mbedtls_strerror() not to recognize `0x80, as it is as a low level error code, but the value belongs to a high level error code.
The valuse should be changed, but it is already merged in Mbed OS
@sbutcher-arm Should we change the value, causing possible ABI issues if users have specifically expect this error code or should we change the limit of the low level error code?

Copy link
Contributor

Choose a reason for hiding this comment

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

@RonEld - Can you please change the line to RESERVED? The value isn't properly allocated, so can be reused at some point in the future. It never touched the Mbed TLS standalone release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I should change this description to 0x0070
What do you want me to change to reserved? Since it hasn't been merged yet to Mbed TLS, why should we reserve this value?

Rename the PLATFORM HW error, to avoid ABI breakage with Mbed OS.
The value changed as well, as previous value was not in the range of
Mbed TLS low level error codes.
@RonEld RonEld dismissed stale reviews from simonbutcher and Patater via a27190b October 15, 2018 13:35
@RonEld RonEld added needs-review Every commit must be reviewed by at least two team members, and removed approved Design and code approved - may be waiting for CI or backports labels Oct 15, 2018
@@ -80,6 +80,7 @@
* CHACHA20 3 0x0051-0x0055
* POLY1305 3 0x0057-0x005B
* CHACHAPOLY 2 0x0054-0x0056
* PLATFORM 1 0x0080-0x0080
Copy link
Contributor

Choose a reason for hiding this comment

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

@RonEld - Can you please change the line to RESERVED? The value isn't properly allocated, so can be reused at some point in the future. It never touched the Mbed TLS standalone release.

library/error.c Outdated
@@ -821,6 +825,11 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
#endif /* MBEDTLS_PADLOCK_C */

#if defined(MBEDTLS_PLATFORM_C)
if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) )
mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware failed platform operation" );
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate you probably haven't changed the error text since the PR was first approved, but the error looks confusing to me. We haven't failed a platform operation - but some crypto operation. Could we change the phrasing to:

PLATFORM - Hardware accelerator failed

It's vaguer, but truer to the intent of the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

1. Change error description to a clearer one.
2. Change value in the error codes ranges description.
@RonEld
Copy link
Contributor Author

RonEld commented Oct 15, 2018

@sbutcher-arm I addressed your comments.
I don't quite follow why you want to reserve 0x0080, since it is not used

@RonEld RonEld removed the needs-review Every commit must be reviewed by at least two team members, label Oct 22, 2018
@simonbutcher simonbutcher added approved Design and code approved - may be waiting for CI or backports needs-review Every commit must be reviewed by at least two team members, labels Oct 22, 2018
@simonbutcher
Copy link
Contributor

I was suggesting to mark 0x0080 to be reserved because we had already used it in Mbed OS, but then had removed it's usage. Technically the value had never been properly allocated, but there was still some risk of collision if someone picked up that transient version of Mbed OS.

It's not a big deal, and if we mark the value as reserved in a year's time no one will remember what for or why, so best left as it is I think.

@simonbutcher simonbutcher removed the needs-review Every commit must be reviewed by at least two team members, label Oct 22, 2018
@simonbutcher simonbutcher merged commit 5267b62 into Mbed-TLS:development Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-platform Portability layer and build scripts enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants