Skip to content

fix: copy ticket key before use to avoid concurrent rotation UAF - #6043

Open
jouho wants to merge 1 commit into
aws:mainfrom
jouho:fix/ticket-key-concurrent-rotation-uaf
Open

fix: copy ticket key before use to avoid concurrent rotation UAF#6043
jouho wants to merge 1 commit into
aws:mainfrom
jouho:fix/ticket-key-concurrent-rotation-uaf

Conversation

@jouho

@jouho jouho commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Goal

Fix a use-after-free in the session ticket encrypt/decrypt paths triggered by concurrent ticket key rotation.

Why

The lookup functions return a raw pointer into the shared, unlocked config->ticket_keys array, and callers hold it across crypto operations. A concurrent s2n_config_add_ticket_crypto_key() can realloc or shift that array, invalidating the pointer. This is an expected usage pattern. The docs explicitly permit rotating keys on a live config. Result: likely a crash, worst case a ticket encrypted with stale key material.

How

Copy the key onto the stack immediately after lookup, before any crypto operations, so no pointer into the shared array survives. Applied at all four call sites (s2n_store_to_cache, s2n_resume_decrypt_session, and the TLS1.2/1.3 NST write paths).

Callouts

  • Closes the memory-safety window without adding locks, consistent with s2n's lock-free design. A benign torn read during the copy is still possible but only degrades to a full-handshake fallback.
  • Lookup functions still return raw pointers, so callers must remember to copy. Removing that footgun is a possible follow-up.

Testing

Existing session ticket and resumption tests continue to pass.

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

@github-actions github-actions Bot added the s2n-core team label Aug 17, 2026
@jouho
jouho requested review from CarolYeh910 and alexw91 August 17, 2026 22:58
@jouho
jouho enabled auto-merge August 19, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants