Skip to content

LOAD_ATTR_SLOT and STORE_ATTR_SLOT don't check the owner's type #99257

Closed

Description

@brandtbucher

When specializing LOAD_ATTR_SLOT, we don't check whether the given member descriptor is valid for the type we got it from.

Here is a problematic example, where one class "borrows" a slot from another:

>>> class Class:
...     __slots__ = ("slot",)
... 
>>> class Sneaky:
...     borrowed = Class.slot
... 
>>> def f(o):
...     return o.borrowed
... 
>>> o = Sneaky()

The unspecialized code behaves correctly:

>>> f(o)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in f
TypeError: descriptor 'slot' for 'Class' objects doesn't apply to a 'Sneaky' object

However, the specialized code crashes, since it is accessing memory past the end of the object:

>>> f(o)
Segmentation fault

We can fix this by performing the same check that the member descriptor performs (PyObject_TypeCheck(obj, descr->d_type)) when specializing.

CC @markshannon

Activity

  1. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.11only security fixes
    type-crashA hard crash of the interpreter, possibly with a core dump
    3.12only security fixes
    on Nov 8, 2022
  2. self-assigned this
    on Nov 8, 2022
  3. added a commit that references this issue on Nov 10, 2022
  4. added a commit that references this issue on Nov 10, 2022
  5. Repository owner moved this from Todo to Done in Release and Deferred blockers 🚫on Nov 10, 2022
  6. added a commit that references this issue on Nov 10, 2022
  7. added a commit that references this issue on Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-crashA hard crash of the interpreter, possibly with a core dump

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions