GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use-after-free in `{Attribute,Name,Import}Error` suggestion generation · Issue #157947 · python/cpython

Use-after-free in {Attribute,Name,Import}Error suggestion generation #157947

New issue
Copy link
New issue
Copy link
Open
Open
Use-after-free in {Attribute,Name,Import}Error suggestion generation#157947
Copy link
Labels
3.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

@stratakis
stratakis
opened on Sep 22, 2026
Issue body actions

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.c hold 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() sets sys.last_value to the live exception before display, which reaches get_suggestions_for_attribute_error():

    PyObject *name = exc->name;         // borrowed
    PyObject *dir = PyObject_Dir(obj);  // runs obj.__dir__() -> arbitrary Python
    calculate_suggestions(dir, name);   // uses stale `name`

AttributeError.name is a T_OBJECT member whose setter decrefs the old value, so code in obj.__dir__() can reach the exception via sys.last_value, do exc.name = ..., and free the borrowed string before calculate_suggestions() dereferences it. Same pattern in the NameError and ImportError paths.

PoC

      import sys
      def fresh_name():
          return ("X" * (4 * 1024 * 1024)) + "!"   # mmap'd -> munmap on free
      class Evil:
          def __dir__(self):
              exc = getattr(sys, "last_value", None)
              if isinstance(exc, AttributeError):
                  exc.name = "replaced"; exc.obj = None
              return ["x"] 
      raise AttributeError("boom", name=fresh_name(), obj=Evil()

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

  • [3.12] gh-157947: Keep exception fields alive during suggestion lookups #157973

Activity

  1. stratakis
    added
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Sep 22, 2026
  2. StanFromIreland
    changed the title [-]Use-after-free in AttributeError/NameError/ImportError suggestion generation (Python/suggestions.c)[/-] [+]Use-after-free in `{Attribute,Name,Import}Error` suggestion generation[/+] on Sep 22, 2026
  3. StanFromIreland
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    3.12only security fixesonly security fixes
    on Sep 22, 2026
  4. StanFromIreland commented on Sep 22, 2026

    @StanFromIreland
    StanFromIreland
    on Sep 22, 2026
    Member
    More actions

    Only 3.10-3.12 need the strong-reference fix.

    This does not qualify as a vulnerability per our security policy (an attacker can't really exploit this), see discussion on the GHSA for more information. Leaving it up to the RM's as to whether they'd like to fix this on their branches.

    CC @pablogsal @Yhg1s

  5. picnixz commented on Sep 22, 2026

    @picnixz
    picnixz
    on Sep 22, 2026
    Member
    More actions

    I do not think it is worth it

    Reacted by Stan Ulbrych
  6. StanFromIreland
    removed
    3.10 (EOL)end of lifeend of life
    on Oct 1, 2026
  7. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
  8. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
  9. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.