Skip to content

Use-after-free for server-side SSLContext with sni_callback #156293

Closed

Description

@gpshead

This was assigned CVE-2026-19445 via our original GHSA report. Edited to fill in some details now that the fix has been released:

Summary

A remote, unauthenticated TLS client can make a Python TLS server dereference and call through a freed ssl.SSLContext object. Setting SSLContext.sni_callback registers the context with OpenSSL as the servername-callback argument without owning a reference, and nothing unregisters it when the context is deallocated; the underlying SSL_CTX outlives the Python object and OpenSSL still consults its callback on a later ClientHello of the same connection. A client provokes that later ClientHello at will (TLS 1.3 HelloRetryRequest, or renegotiation where the OpenSSL build permits it) and chooses its timing. Servers that select certificates from sni_callback in the documented way and do not keep their own reference to the callback-bearing context (for example gunicorn with an SNI-selecting ssl_context hook) crash or corrupt memory; on release builds the value used as the callback pointer has been observed to come from other clients' request bytes.

Impact

Use-after-free / memory corruption in the TLS server path, triggered pre-authentication on the first flight of a connection, with the timing of the use chosen by the peer. Observed outcomes depend on what reuses the freed allocation: deterministic crash, the stale callback slot has been seen as NULL (silently skipped), or as a pointer to an unrelated live object (invoked as the SNI callback), and as bytes from concurrent requests. The latter is what makes this a serious security issue.

Mitigation on unpatched versions

Keep a long-lived reference to every ssl.SSLContext that has sni_callback set (gunicorn: build the context once and return the same object from the hook); on OpenSSL 1.1.1 builds additionally set ssl.OP_NO_RENEGOTIATION on that (initial) context.

Credit

Discovered by Gregory P. Smith in collaboration with Claude and Anthropic Research

Linked PRs

Activity

  1. added
    triagedThe issue has been accepted as valid by a triager.
    on Aug 23, 2026
  2. changed the title [-][placeholder] reserving a number for an upcoming fix[/-] [+]Use-after-free for server-side SSLContext with sni_callback[/+] on Sep 30, 2026
  3. added 2 commits that reference this issue on Sep 30, 2026
  4. added 4 commits that reference this issue on Sep 30, 2026
  5. gpshead commented on Sep 30, 2026

    @gpshead
    MemberAuthor

    see my gpshead fork's gh-156293-ssl-sni-callback-* branches for pre-prepared and tested backports for this to 3.10 through 3.15. @sethmlarson @hugovk

  6. added a commit that references this issue on Sep 30, 2026
  7. hugovk commented on Sep 30, 2026

    @hugovk
    Member

    We already have 3.12-3.15 backports merged.

    I'll open 3.10-3.11 backports from the ready forks at gh-156293-ssl-sni-callback-*.

  8. gpshead commented on Sep 30, 2026

    @gpshead
    MemberAuthor

    dueling fingers. opened. :)

  9. gpshead commented on Sep 30, 2026

    @gpshead
    MemberAuthor

    also, i verified that the existing backports matched what was expected.

  10. added 2 commits that reference this issue on Oct 1, 2026
  11. gpshead commented on Oct 1, 2026

    @gpshead
    MemberAuthor

    If any redistributors of beyond EOL versions need one, a 3.9 patch can be found in gpshead@c6c421e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions