Skip to content

GH-159101: Fix UAF when tp_finalize changes the base class - #159888

Open
sergey-miryanov wants to merge 4 commits into
python:mainfrom
sergey-miryanov:bug/159101-uaf-after-finalize
Open

sergey-miryanov wants to merge 4 commits into
python:mainfrom
sergey-miryanov:bug/159101-uaf-after-finalize

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

There are two issues to address.

First, we fix the UAF in PyObject_CallFinalizer. We set the FINALIZED flag before calling tp_finalize, so we don't need to call _PyType_IS_GC again. Both gc.c and gc_free_threading.c do the same.

Second, after calling PyObject_CallFinalizerFromDealloc, we extract the type of self again to get the updated type, and the rest works correctly. We do the same for tp_del later in the code.

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-10-20-20-38-38.gh-issue-159101.vFwrZY.rst Outdated
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

@nascheme @pablogsal Could you please take a look?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants