-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Use-after-free in {Attribute,Name,Import}Error suggestion generation #157947
Copy link
Copy link
Open
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
Metadata
Metadata
Assignees
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Crash report
What happened?
Summary
This is a Use-after-free (CWE-416), interpreter crash. Only reachable by running crafted Python, which per the Python security policy is not a security boundary, so opening it as a regular bug per the request of the Python Security team.
The "Did you mean: ...?" suggestion helpers in
Python/suggestions.chold borrowed references to exception fields across PyObject_Dir(), which can run arbitrary Python. Re-entrant code that reassigns those fields frees them mid-use, causing a use-after-free during exception display. Affects 3.10-3.12.Details
_PyErr_PrintEx()setssys.last_valueto the live exception before display, which reachesget_suggestions_for_attribute_error():AttributeError.nameis aT_OBJECTmember whose setter decrefs the old value, so code inobj.__dir__()can reach the exception viasys.last_value, doexc.name = ..., and free the borrowed string beforecalculate_suggestions()dereferences it. Same pattern in the NameError and ImportError paths.PoC
python3.12 repro.py -> SIGSEGV in PyUnicode_AsUTF8AndSize <- calculate_suggestions.
Fixed incidentally in 3.13 (#110721 which moved display to the traceback module). Only 3.10-3.12 need the strong-reference fix.
CPython versions tested on:
3.10, 3.11, 3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs