Skip to content

Reject out-of-bounds ALPN length in ssl_context_load#10792

Open
nvxbug wants to merge 1 commit into
Mbed-TLS:developmentfrom
nvxbug:ssl-context-load-alpn-bounds
Open

Reject out-of-bounds ALPN length in ssl_context_load#10792
nvxbug wants to merge 1 commit into
Mbed-TLS:developmentfrom
nvxbug:ssl-context-load-alpn-bounds

Conversation

@nvxbug

@nvxbug nvxbug commented Jun 25, 2026

Copy link
Copy Markdown

Description

ssl_context_load() reads the serialized ALPN protocol length as a single byte and then runs memcmp(p, *cur, alpn_len) against each configured protocol, but it never checks that alpn_len bytes still remain before end. A corrupted or truncated serialized context whose ALPN length is larger than the bytes that actually follow makes that memcmp read past the end of the buffer.

The added check bounds alpn_len against the remaining data right after the length is read, the same way the DTLS CID lengths a few lines above are bounded. Keeping the check next to the read leaves both the comparison loop and the p += alpn_len advance inside the buffer. The regression test under test_suite_ssl serializes a context with a negotiated protocol, enlarges the stored length, and checks the load is rejected; it trips ASan at the memcmp before the fix.

PR checklist

  • changelog provided
  • framework PR not required
  • TF-PSA-Crypto development PR not required
  • TF-PSA-Crypto 1.1 PR not required
  • mbedtls development PR this PR
  • mbedtls 4.1 PR not part of this PR, happy to backport if wanted
  • mbedtls 3.6 PR not part of this PR, happy to backport if wanted
  • tests provided

The serialized ALPN length was passed to memcmp() against each configured protocol without checking it against the remaining serialized data, so a malformed context could read past the end of the buffer. Bound it before the comparison, like the adjacent CID fields.

Signed-off-by: Naveed <naveed@bugqore.com>
@yiwu0b11 yiwu0b11 added bug needs-review Every commit must be reviewed by at least two team members, component-tls needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review priority-low Low priority - this may not receive review soon size-xs Estimated task size: extra small (a few hours at most) labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug component-tls needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review priority-low Low priority - this may not receive review soon size-xs Estimated task size: extra small (a few hours at most)

Projects

Status: No status
Status: In Development

Development

Successfully merging this pull request may close these issues.

2 participants