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

Update to mbedtls 2.28.0 #173

Merged
merged 10 commits into from
Feb 7, 2022
Merged

Update to mbedtls 2.28.0 #173

merged 10 commits into from
Feb 7, 2022

Conversation

MihirLuthra
Copy link
Member

No description provided.

MihirLuthra and others added 7 commits January 5, 2022 16:19
1. Added conditional compilation flags "MBEDTLS_FORCE_AESNI" and "MBEDTLS_FORCE_PADLOCK"
2. This allows us to supress cpuid based feature detection on sgx platforms.
3. "MBEDTLS_FORCE_AESNI" gets set if "force_aesni_support" flag is enabled.
4. Please refer to the previous commit for rust side changes.

(cherry picked from commit d2317b0)
(cherry picked from commit 38522c2)
@MihirLuthra MihirLuthra requested a review from jethrogb January 5, 2022 15:38
mbedtls_pk_sign() and mbedtls_pk_verify() and their extended and
restartable variants now require at least the specified hash length if
nonzero. Before, for RSA, hash_len was ignored in favor of the length of
the specified hash algorithm.

See: https://github.com/ARMmbed/mbedtls/releases
@MihirLuthra MihirLuthra force-pushed the mihir/update-to-2.28 branch from 4bda3a2 to 96f37bd Compare January 5, 2022 17:43
@@ -146,6 +146,7 @@ const DEFAULT_DEFINES: &'static [CDefine] = &[
("MBEDTLS_AES_ROM_TABLES", Undefined),
("MBEDTLS_AES_FEWER_TABLES", Undefined),
("MBEDTLS_CAMELLIA_SMALL_MEMORY", Undefined),
("MBEDTLS_CHECK_RETURN_WARNING", Undefined),
Copy link
Member

Choose a reason for hiding this comment

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

Let's set this. Bindgen ignores it but it may be able to use it in the futures.

@@ -377,6 +379,7 @@ const DEFAULT_DEFINES: &'static [CDefine] = &[
("MBEDTLS_PLATFORM_VSNPRINTF_MACRO", Undefined), // default: vsnprintf
("MBEDTLS_PLATFORM_NV_SEED_READ_MACRO", Undefined), // default: mbedtls_platform_std_nv_seed_read
("MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO", Undefined), // default: mbedtls_platform_std_nv_seed_write
("MBEDTLS_CHECK_RETURN", Undefined), // default: __attribute__((__warn_unused_result__))
Copy link
Member

Choose a reason for hiding this comment

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

Missing MBEDTLS_IGNORE_RETURN

Copy link
Member Author

@MihirLuthra MihirLuthra Feb 7, 2022

Choose a reason for hiding this comment

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

As discussed, not adding this as this is a function-like macro (although, I am less knowledgeable about why). For reference:

/** \def MBEDTLS_IGNORE_RETURN
 *
 * This macro requires one argument, which should be a C function call.
 * If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this
 * warning is suppressed.
 */
//#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result))

@@ -1259,23 +1259,42 @@ iy6KC991zzvaWY/Ys+q/84Afqa+0qJKQnPuy/7F5GkVdQA/lfbhi
];

for digest in &digests {
let digest = *digest;
Copy link
Member

Choose a reason for hiding this comment

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

Making changes to the test is not appropriate as this implies a public API change, which is backwards-incompatible. Instead, change Pk::sign to deal with the new behavior. The release notes imply this is a RSA-specific change, so please also add some ECDSA tests to make sure you're not making any changes to the behavior there.

Copy link
Member

Choose a reason for hiding this comment

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

Also please add a test with hash=&[] as the release notes indicate special before if zero.

Copy link
Member Author

Choose a reason for hiding this comment

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

What kind of changes are you expecting in Pk::sign? AFAIU, the change was a bugfix for a behaviour that was already incorrect. This change was backported in 2.26 requiring the argument hash_len to be at least the length of message digest. In 2.28, the length needs to be equal.
Passing a lesser length is surely a bug but we could probably add a patch to vendor to accept hash_len which is at least the length of message digest instead of equal and bump the patch version of mbedtls crate?

References:
[1] Mbed-TLS/mbedtls#4561
[2] Mbed-TLS/mbedtls#4707

Copy link
Member

Choose a reason for hiding this comment

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

When I wrote my comment I was thinking we could make hash shorter in sign/verify. But actually, silently signing less than the full hash input by the user is also bad. So I think we need to make the incompatible change for security reasons. I've simplified your changes though (force-pushed onto your branch), please review.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, those changes LGTM.

Jethro Beekman and others added 2 commits February 4, 2022 14:12
mbedtls_pk_sign() and mbedtls_pk_verify() and their extended and
restartable variants now require at least the specified hash length if
nonzero. Before, for RSA, hash_len was ignored in favor of the length of
the specified hash algorithm.

See: https://github.com/ARMmbed/mbedtls/releases
Although, bindgen needs .enable_function_attribute_detection()
to process __attribute__((__warn_unused_result__)) because parsing
attrs can be really slow in certain cases. Benches were performed
to confirm our case doesn't face that issue.

References:
rust-lang/rust-bindgen#2149
rust-lang/rust-bindgen#1465
rust-lang/rust-bindgen#1466
rust-lang/rust-bindgen#1467
@jethrogb
Copy link
Member

jethrogb commented Feb 7, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 7, 2022

Build succeeded:

@bors bors bot merged commit 4fb6294 into master Feb 7, 2022
@Taowyoo Taowyoo deleted the mihir/update-to-2.28 branch October 20, 2023 16:26
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.

3 participants