Skip to content

std.tls: a handshake message must lie inside the record received, and the certificate lengths inside the message (#1062) - #2667

Merged
ehartford merged 1 commit into
fix-2648from
fix-1062
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-2648from
fix-1062

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: tls_recv_server_handshake (lib/std/tls.w) decoded each
message's 3-byte length from the server and checked only that its 4-byte
header fit the record; tls_hs_hash_update, the ServerHello parse, the
certificate copy and the SKE reads then used it as given. A server that
claims a 16 MiB ServerHello in a 4-byte record made the client read far
past the 16640-byte record buffer: lldb on the test binary stops at
EXC_BAD_ACCESS in sha256_update(data="\x02\xff\xff\xff"), the handshake
hash of that header.

A message longer than the rest of the record fails the handshake; the first
certificate's length must fit its message; cert_len is the bytes copied.

Test: test/behavior/behav_1062_tls_handshake_length_past_record.w (a
loopback server sends the record; before the fix the client exits 139).

Closes #1062

… the certificate lengths inside the message (#1062)

Root cause: tls_recv_server_handshake (lib/std/tls.w) decoded each
message's 3-byte length from the server and checked only that its 4-byte
header fit the record; tls_hs_hash_update, the ServerHello parse, the
certificate copy and the SKE reads then used it as given. A server that
claims a 16 MiB ServerHello in a 4-byte record made the client read far
past the 16640-byte record buffer: lldb on the test binary stops at
EXC_BAD_ACCESS in sha256_update(data="\x02\xff\xff\xff"), the handshake
hash of that header.

A message longer than the rest of the record fails the handshake; the first
certificate's length must fit its message; cert_len is the bytes copied.

Test: test/behavior/behav_1062_tls_handshake_length_past_record.w (a
loopback server sends the record; before the fix the client exits 139).
@ehartford
ehartford added this pull request to stack #2668 October 25, 2026 22:01
@ehartford ehartford changed the title fix 1062 std.tls: a handshake message must lie inside the record received, and the certificate lengths inside the message (#1062) Oct 25, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on the stack top 9f92dbb9b (with run tools/battery.w, pinned seed nightly-20261025-local-1-c88f3eeff0bc): gate, UAT and battery-checks all green (out/battery/status.txt). Covers #2660 through #2667 (#2326 in part, #2319, #2316, #2270, #2268, #1146, #2648, #1062).

@ehartford
ehartford marked this pull request as ready for review October 25, 2026 22:13
@ehartford
ehartford merged commit e3b0ad0 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-1062 branch October 25, 2026 22:14
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.

[crypto] TLS handshake parses wire lengths unclamped (cert/hs_len vs record bounds)

1 participant