Skip to content

[3.10] gh-144833: Fix use-after-free in SSL module when SSL_new() fails (GH-144843) - #144862

Merged
pablogsal merged 1 commit into
python:3.10from
miss-islington:backport-c91638c-3.10
Mar 2, 2026
Merged

pablogsal merged 1 commit into
python:3.10from
miss-islington:backport-c91638c-3.10

Conversation

@miss-islington

@miss-islington miss-islington commented Feb 16, 2026 •

Copy link
Copy Markdown
Contributor

In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self)
was called before _setSSLError(get_state_ctx(self), ...), causing
a use-after-free. Additionally, get_state_ctx() was called with
self (PySSLSocket*) instead of sslctx (PySSLContext*), which is
a type confusion bug.

Fix by calling _setSSLError() before Py_DECREF() and using
sslctx instead of self for get_state_ctx().
(cherry picked from commit c91638c)

Co-authored-by: Ramin Farajpour Cami ramin.blackhat@gmail.com

pythonGH-144843)

In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self)
was called before _setSSLError(get_state_ctx(self), ...), causing
a use-after-free. Additionally, get_state_ctx() was called with
self (PySSLSocket*) instead of sslctx (PySSLContext*), which is
a type confusion bug.

Fix by calling _setSSLError() before Py_DECREF() and using
sslctx instead of self for get_state_ctx().
(cherry picked from commit c91638c)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
@pablogsal
pablogsal merged commit 4be624a into python:3.10 Mar 2, 2026
15 of 17 checks passed
@miss-islington
miss-islington deleted the backport-c91638c-3.10 branch March 2, 2026 22:55
icanhasmath pushed a commit to ActiveState/cpython that referenced this pull request Oct 28, 2026
…() fails (pythonGH-144843) (python#144862)

pythongh-144833: Fix use-after-free in SSL module when SSL_new() fails (pythonGH-144843)

In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self)
was called before _setSSLError(get_state_ctx(self), ...), causing
a use-after-free. Additionally, get_state_ctx() was called with
self (PySSLSocket*) instead of sslctx (PySSLContext*), which is
a type confusion bug.

Fix by calling _setSSLError() before Py_DECREF() and using
sslctx instead of self for get_state_ctx().
(cherry picked from commit c91638c)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
(cherry picked from commit 4be624a)
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.

5 participants