Skip to content

[3.10] gh-156293: Use-after-free for server-side SSLContext with sni_callback (GH-158504) - #158524

Merged
pablogsal merged 2 commits into
python:3.10from
gpshead:gh-156293-ssl-sni-callback-3.10
Oct 1, 2026
Merged

pablogsal merged 2 commits into
python:3.10from
gpshead:gh-156293-ssl-sni-callback-3.10

Conversation

@gpshead

@gpshead gpshead commented Sep 30, 2026

Copy link
Copy Markdown
Member

…ugh a released SSLContext

The servername (SNI) callback located its SSLContext through a borrowed
pointer registered with OpenSSL, which can outlive the SSLContext object.
Look the context up from the SSL object instead, and unregister the
callback when the context is deallocated.

Backport of 87665c9,
adapted to this branch's servername callback code.
@pablogsal
pablogsal merged commit ec44b5a into python:3.10 Oct 1, 2026
17 checks passed
icanhasmath pushed a commit to ActiveState/cpython that referenced this pull request Oct 28, 2026
…h sni_callback (pythonGH-158504) (python#158524)

* [3.10] pythongh-156293: ssl: do not call the servername callback through a released SSLContext

The servername (SNI) callback located its SSLContext through a borrowed
pointer registered with OpenSSL, which can outlive the SSLContext object.
Look the context up from the SSL object instead, and unregister the
callback when the context is deallocated.

Backport of 87665c9,
adapted to this branch's servername callback code.

* [3.10] pythongh-156293: Document sni_callback dispatch after a context switch

(cherry picked from commit ec44b5a)

3.9.25.x: hand-merged into 3.9's _servername_callback(), which still
names the context ssl_ctx; Py_NewRef()/Py_XNewRef() (3.10+) are
spelled as Py_INCREF() and the 3.9 PySSLSocket_Check() assert is kept.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

2 participants