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

[tls13_mps] Fixes to clang 12 compilation issues, removing trailing whitespace #60

Open
wants to merge 8 commits into
base: tls13-prototype
Choose a base branch
from

Conversation

oesh
Copy link

@oesh oesh commented Nov 12, 2020

This commit prevents early return when TLS1_3 enabled,
TLS1_2 disabled and SOME_MODES_USE_MAC enabled.

Without the commit, the compilation fails due to unreachable code, e.g.

/Users/oshapira/git/mbedtls/library/ssl_msg.c:1723:13: error: code will never be executed [-Werror,-Wunreachable-code]
        if( mbedtls_ssl_safer_memcmp( mac_peer, mac_expect,
            ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/oshapira/git/mbedtls/library/ssl_msg.c:1625:9: error: code will never be executed [-Werror,-Wunreachable-code]
        rec->data_len -= padlen;
        ^~~
2 errors generated.

Signed-off-by: Omer Shapira [email protected]

This commit prevents early return when TLS1_3 enabled,
TLS1_2 disabled and SOME_MODES_USE_MAC enabled.

Without the commit, the compilation fails due to unreachable code, e.g.

```
/Users/oshapira/git/mbedtls/library/ssl_msg.c:1723:13: error: code will never be executed [-Werror,-Wunreachable-code]
        if( mbedtls_ssl_safer_memcmp( mac_peer, mac_expect,
            ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/oshapira/git/mbedtls/library/ssl_msg.c:1625:9: error: code will never be executed [-Werror,-Wunreachable-code]
        rec->data_len -= padlen;
        ^~~
2 errors generated.

```

Signed-off-by: Omer Shapira <[email protected]>
@zhihan
Copy link

zhihan commented Nov 12, 2020

Nice!

Recent clang fails to accept unannotated fallthrough in a switch case,
leading to a compilation error:

/Users/oshapira/git/mbedtls/library/mps/mps.c:2173:13: note: insert 'break;' to avoid fall-through
            default:

Signed-off-by: Omer Shapira <[email protected]>
Removed trailing whitespace.

Signed-off-by: Omer Shapira <[email protected]>
@oesh oesh changed the title [tls13_mps] Fixed compilation errors due to unreachable code [tls13_mps] Fixes to clang 12 compilation issues, removing trailing whitespace Nov 13, 2020
@@ -1613,6 +1613,9 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
else
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
MBEDTLS_SSL_PROTO_TLS1_2 */
#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
if( transform->minor_ver != MBEDTLS_SSL_MINOR_VERSION_4 )
Copy link
Collaborator

Choose a reason for hiding this comment

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

@oesh The present code-path is for CBC mode encryption, which isn't supported in TLS 1.3. It is therefore an error if we get to this point if transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_4, and it seems that the previous version of the code was right. What was the motivation for the change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about guarding the entire CBC codepath with #if defined( SSL3 || TLS1 || TLS1_1 || TLS1_2 ) ... #endif? That should resolve the issue.

@@ -1710,6 +1713,9 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
else
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
MBEDTLS_SSL_PROTO_TLS1_2 */
#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above.

Copy link
Collaborator

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

Thanks @oesh for spotting that and for opening a PR!

I believe that the issue should be fixed in a slightly different way than proposed, by guarding the entire CBC encryption/decryption logic with a "Some TLS < 1.3 version enabled" guard. Such guard is redundant in previous versions of Mbed TLS, but we'll need it here -- and likely in other places, too -- now that we're adding support for TLS 1.3.

Would you be willing to adjust the PR accordingly?

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