Skip to content

Fix ClientHello padding flag and HPKE setup failure state - #3885

Open
prasden wants to merge 2 commits into
aws:mainfrom
prasden:clienthello-padding-flag
Open

prasden wants to merge 2 commits into
aws:mainfrom
prasden:clienthello-padding-flag

Conversation

@prasden

@prasden prasden commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Context and motivation

  1. Some servers reject a ClientHello whose final extension is empty. AWS-LC avoids this by adding a 1-byte padding extension when last_was_empty is true. The extension loop sets last_was_empty = (bytes_written == 4) after every extension, including extensions that write nothing. An extension that writes nothing has bytes_written == 0, which sets the flag to false. If an empty extension is followed only by extensions that write nothing, the flag ends as false and no padding is added.

  2. When HPKE setup fails, it should leave the context empty. It did not. The KEM, KDF and AEAD fields stayed set, and the getters returned them instead of NULL. Some setup functions also returned before they zeroed the context.

Description of changes

9284eb2 updates last_was_empty only when an extension writes bytes. Custom extensions now update it too. Default TLS 1.0 and TLS 1.1 ClientHellos grow by 5 bytes because they now end with the padding extension. TLS 1.2 and TLS 1.3 defaults do not change.

2f9e084 zeroes the HPKE context at the start of every setup function and in EVP_HPKE_CTX_cleanup. A failed setup now leaves the context empty. The getters then return NULL and cleanup is safe.

Testing

Updated the existing ClientHello and HPKE tests to cover both bugs, added SSLTest.PaddingAfterEmptyCustomExtension for custom extensions, and ran the full ssl_test and the HPKE tests under ASan.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@prasden prasden changed the title Keep the final ClientHello extension non-empty Fix ClientHello padding flag and HPKE setup failure state Dec 3, 2026
@prasden
prasden marked this pull request as ready for review December 3, 2026 22:51
@prasden
prasden requested a review from a team as a code owner December 3, 2026 22:51
@sgmenda sgmenda self-assigned this Dec 3, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.80%. Comparing base (aa8f2e3) to head (2f9e084).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3885      +/-   ##
==========================================
- Coverage   79.02%   78.80%   -0.23%     
==========================================
  Files         716      716              
  Lines      135498   135529      +31     
  Branches    19535    19533       -2     
==========================================
- Hits       107079   106804     -275     
- Misses      27373    27681     +308     
+ Partials     1046     1044       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🔒 Security Review — View Report

Please review before merging.

Comment thread ssl/ssl_encoding_test.cc
TEST(SSLTest, PaddingAfterEmptyCustomExtension) {
bssl::UniquePtr<SSL_CTX> ctx(SSL_CTX_new(TLS_method()));
ASSERT_TRUE(ctx);
ASSERT_TRUE(SSL_CTX_set_max_proto_version(ctx.get(), TLS1_1_VERSION));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test doesn't cover the custom_extensions.cc change: the empty session_ticket extension already leaves last_was_empty true, so the test still passes with that change reverted. Disabling tickets makes the custom extension the only empty one.

  SSL_CTX_set_options(ctx.get(), SSL_OP_NO_TICKET);

@sgmenda sgmenda Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1. I checked: with the last_was_empty update in custom_extensions.cc removed, the test still passes as written. It only fails when SSL_OP_NO_TICKET is set.

Comment thread crypto/hpke/hpke_test.cc
expect_no_key_set();

ScopedEVP_HPKE_CTX ctx;
auto poison_ctx = [&] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO the 0xab poisoning (here and in AuthModeNotSupported) makes a regression undefined behavior rather than a test failure, since the scoped context's cleanup then calls through a garbage aead pointer; with the fix reverted, this test hangs in EVP_AEAD_CTX_cleanup on my macOS ASan build. I think it would be better to set the context up successfully first and then check that the getters return NULL after the failed setup, as SetupSenderBufferTooSmall does.

@sgmenda sgmenda Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1. I checked: with the HPKE change reverted, the 0xab version of ZeroedKeyFailsCleanly segfaults crypto_test on Linux, while a live-context setup followed by NULL-getter checks fails with plain assertions.

Comment thread ssl/custom_extensions.cc
if (ssl->server) {
return 0;
}
*out_len = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this bug wasn't introduced in this PR, but I believe its the one leading to the msan failures. I checked locally with clang 15 and -fsanitize-memory-param-retval

Suggested change
*out = nullptr;
*out_len = 0;

This branch has not been deployed

No deployments
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