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

Feature unavailable errors #2054

Merged
merged 3 commits into from
Nov 12, 2018

Conversation

RonEld
Copy link
Contributor

@RonEld RonEld commented Oct 4, 2018

Description

  1. Add a common error code for alternative implementations, returning MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
  2. Remove all feature specific errors for Feature "Not Supported and for the HW acceleration failure.

Dependent on #1993 to be merged first
One of the PRs that supersedes #1716

Status

HOLD

Requires Backporting

NO

Migrations

If there is any API change, what's the incentive and logic for it.

YES

Removing existing error codes may result n backwards incompatibility. Developers May need to change their returned error codes for their alternative implementations. In addition, If a specific error code is expected, it should be changed as well.
The incentive is to have one common error code for a feature that is not supported by the underlying HW accelerator, which makes tests and applications simpler and readable.

This may result in future ABI break, since removed error codes might be reused in the future,

Additional comments

Any additional information that could be of interest

The following FEATURE UNAVAILABLE errors were kept, as they actually mean that a specific feature is currently unavailable, because of missing configuration or other reasons, but are not related to the alternative implementation:

MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE
MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE
MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE
MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE
MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE
MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE
MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE

In addition, MBEDTLS_ERR_SSL_HW_ACCEL_FAILED was kept as it is a specific TLS feature.

Open question: should have MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE been removed?

Todos

  • Tests
  • Documentation
  • Changelog updated
  • Backported

@RonEld RonEld requested a review from Patater October 4, 2018 11:33
* GCM 2 0x0012-0x0014
* BLOWFISH 2 0x0016-0x0018
* THREADING 3 0x001C-0x001E
* AES 3 0x0020-0x0022 0x0021-0x0021
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit funny. Isn't 0x0021 within the range of 0x0020-0x0022 Why does it need a separate entry?

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 left is the even error codes, the right are the odd error codes

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. THREADING doesn't do that. BLOWFISH doesn't do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind. BLOWFISH doesn't do this because we deleted 0x0017. THREADING also doesn't have odd error codes.

* BLOWFISH 2 0x0016-0x0018
* THREADING 3 0x001C-0x001E
* AES 3 0x0020-0x0022 0x0021-0x0021
* CAMELLIA 2 0x0024-0x002
Copy link
Contributor

Choose a reason for hiding this comment

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

0x002 looks wrong.

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, it's a typo

* \return #MBEDTLS_ERR_GCM_HW_ACCEL_FAILED or a cipher-specific
* error code if the encryption or decryption failed.
* \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths are not valid or
* a cipher-specific error code if the encryption
Copy link
Contributor

Choose a reason for hiding this comment

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

A platform error code is not a cipher-specific error code. What makes sense to say here? Should we list MBEDTLS_ERR_PLATFORM_HW_FAILED explicitly or say "a cipher- or platform-specific error code"? Same goes for other similar comments for other functions and files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, but the MBEDTLS_ERR_PLATFORM_HW_FAILED is a generic error that is returned by the platform. The cipher specific code is because gcm is part of the cipher module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where in this function's documentation do we indicate that you might receive a platform error code? Or is that universally implied or expressly written elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be universally implied. It will be updated in the relevant KB article, about implementing alternative modules

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@RonEld RonEld added enhancement mbed TLS team needs-design-approval component-crypto Crypto primitives and low-level interfaces component-platform Portability layer and build scripts and removed component-crypto Crypto primitives and low-level interfaces labels Oct 4, 2018
@RonEld
Copy link
Contributor Author

RonEld commented Oct 7, 2018

@Patater I addressed your comments

itayzafrir
itayzafrir previously approved these changes Oct 8, 2018
Copy link
Contributor

@itayzafrir itayzafrir left a comment

Choose a reason for hiding this comment

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

LGTM

@RonEld
Copy link
Contributor Author

RonEld commented Oct 9, 2018

CI failed in timing test, which is a known issue

@RonEld
Copy link
Contributor Author

RonEld commented Oct 9, 2018

@Patater Thank you for your review.
Do you have additional comments? Is this approved for design?

Patater
Patater previously approved these changes Oct 9, 2018
@RonEld
Copy link
Contributor Author

RonEld commented Oct 9, 2018

@Patater @itayzafrir Thank you for reviewing.

I would like to hear your comments about the additional comments in the description.

@Patater
Copy link
Contributor

Patater commented Oct 9, 2018

Should MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE have been removed?

I could see that making sense, but it's also OK as-is, IMO.

@Patater Patater added approved Design and code approved - may be waiting for CI or backports needs-preceding-pr Requires another PR to be merged first labels Oct 9, 2018
@@ -43,6 +43,9 @@
#include "platform_time.h"
#endif

#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware failed platform operation. */
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0082 /**< The requested feature is not supported by the platform */
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 value probably needs to be changed.
I get the following:

programs/util/strerror 0x82
Last error was: -0x0082 - UNKNOWN ERROR CODE (0080) : BIGNUM - An error occurred while reading from or writing to a file

I'll change to 0x78, assuming the parsing will work

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 problem is that our low level error codes are defined as:

(0x0002-0x007E, 0x0003-0x007F)

@RonEld RonEld added needs-work and removed approved Design and code approved - may be waiting for CI or backports labels Oct 14, 2018
@RonEld RonEld dismissed stale reviews from Patater and itayzafrir via a7307a2 October 22, 2018 13:23
@RonEld
Copy link
Contributor Author

RonEld commented Oct 22, 2018

@Patater @itayzafrir I have updated the error code value.
Please review

@RonEld RonEld added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Oct 22, 2018
@itayzafrir
Copy link
Contributor

itayzafrir commented Oct 24, 2018

Looks good to me. Note there's a typo in commit message for e9afdd2, rage -> range.

@RonEld
Copy link
Contributor Author

RonEld commented Nov 7, 2018

As discussed offline, I have returned the removed error codes, for API compatibility sake, and made them deprecated
cc @Patater @itayzafrir

#define MBEDTLS_DEPRECATED
#endif

#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE static inline int MBEDTLS_DEPRECATED( void ){ return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ); }
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What's the name of this inline function?
  • Why do we need an inline function? Add a comment.
  • I think I'd rather update our test scripts to work with constant deprecation than to use inline functions to work around the scripts' limitations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the name of this inline function?
Copy paste error. I'll add names to the functions

Why do we need an inline function? Add a comment.

I couldn't find another way to deprecate MACROs. If I add a warning, we get compilation warnings, and thus compilation errors when warnings are treated as errors. see https://stackoverflow.com/questions/2681259/how-to-deprecate-a-macro-in-gcc

I think I'd rather update our test scripts to work with constant deprecation than to use inline functions to work around the scripts' limitations.

Me too, but how do you suggest we make the constant deprecations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that all.sh checks explicitely for MBEDTLS_DEPRECATED_WARNINGS and treat warnings as errors:

msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
cleanup
cp "$CONFIG_H" "$CONFIG_BAK"
scripts/config.pl full
scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
# Build with -O -Wextra to catch a maximum of issues.
make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests

msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
# No cleanup, just tweak the configuration and rebuild
make clean
scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
# Build with -O -Wextra to catch a maximum of issues.
make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests

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 How about we go with our original plan and define the MACROS as the platform errors, but not using the MBEDTLS_DEPRECATED_WARNING?

@RonEld
Copy link
Contributor Author

RonEld commented Nov 7, 2018

As discussed offline, I dropped the deprecation of the constant, and kept the commit for the build error

cc @Patater @itayzafrir

@RonEld RonEld force-pushed the feature_unavailable_errors branch 3 times, most recently from bc4dd9f to ac0fb67 Compare November 7, 2018 14:40
@Patater
Copy link
Contributor

Patater commented Nov 9, 2018

CI failure is timing-suite on FreeBSD, a known issue.

Patater
Patater previously approved these changes Nov 9, 2018
dgreen-arm
dgreen-arm previously approved these changes Nov 9, 2018
Add a common error for the feature unavailable, in the
platform module.
@Patater Patater dismissed stale reviews from dgreen-arm and themself via e9ed646 November 9, 2018 14:33
@Patater
Copy link
Contributor

Patater commented Nov 9, 2018

Rebased to add back in and deprecate the deprecated errors. Updated ChangeLog wording slightly.

Old branch at https://github.com/Patater/mbedtls/tree/dev/RonEld/feature_unavailable_errors

Copy link
Contributor

@dgreen-arm dgreen-arm left a comment

Choose a reason for hiding this comment

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

MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED was removed in the previous version, it should probably get a deprecated warning now.

Ron Eldor added 2 commits November 9, 2018 15:01
Deprecate the module-specific XXX_HW_ACCEL_FAILED and
XXX_FEATURE_UNAVAILABLE errors, as alternative implementations should now
return `MBEDTLS_ERR_PLATFORM_HW_FAILED` and
`MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED`.
Add the ChangeLog entry describing the change.
@Patater
Copy link
Contributor

Patater commented Nov 9, 2018

Fixed in original commit

Copy link
Contributor

@simonbutcher simonbutcher left a comment

Choose a reason for hiding this comment

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

I think we need to change the ChangeLog (which I can do if you agree), and we should schedule work to deprecate the constants differently at a later date (including moving the comments to doxygen).

@@ -2,6 +2,10 @@ mbed TLS ChangeLog (Sorted per branch, date)

= mbed TLS x.x.x branch released xxxx-xx-xx

API Changes
* Add a common error code for a feature that is not supported by the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can be specific and say MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED has been added,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, specific is better.

@@ -24,6 +28,12 @@ Features
hash and signature sizes that comply with FIPS 186-4, including SHA-512
with a 1024-bit key.

New deprecations
* All the current module specific errors that mean a feature is not available
are deprecated, so the platform error should be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can specify what we mean here. eg.

All the current module specific errors that mean a feature is not available, such as MBEDTLS_ERR_XXX_FEATURE_UNAVAILABLE, are deprecated.

* All the current module specific errors that mean a feature is not available
are deprecated, so the platform error should be used.
* All the module specific generic hardware accelaration errors that existed
are deprecated, so the platform error should be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. We can show an example symbol,

@@ -60,7 +60,11 @@

/* Error codes in range 0x0021-0x0025 */
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */

/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker because there's precedent, but why have the statement on the symbol being deprecated above it and not in the doxygen comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what the best way for our library to document or tell the compiler that a define is deprecated, yet. Copied the approach used previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is a deprecated feature for doxygen, I think it is better. The approach use previously was on a file that is not part of the doxygen headers.

@Patater
Copy link
Contributor

Patater commented Nov 9, 2018

Yes, please feel free to update the ChangeLog as desired.

@simonbutcher
Copy link
Contributor

retest

@simonbutcher simonbutcher added needs-ci Needs to pass CI tests approved Design and code approved - may be waiting for CI or backports and removed needs-ci Needs to pass CI tests labels Nov 9, 2018
@simonbutcher simonbutcher merged commit 6aa9fb4 into Mbed-TLS:development Nov 12, 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.

5 participants