Skip to content

specialized PRECALL opcodes don't check types #92063

Closed

Description

@sweeneyde

On the main branch, on both Windows and Linux, this crashes:

class Thing:
    pass

thing = Thing()

for i in range(10):
    print(i)
    try:
        str.upper(thing)
    except TypeError:
        pass

print("ok")

Other methods like str.split, bytes.split, and list.sort fail similarly. I caught this by running

./python -m test test_descr -m test_proxy_call -R3:20

Looking through stack traces, it appears the failure is on the res = cfunc(...) call in PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS instruction. It looks to be a 3.11-only bug.

Activity

  1. added
    3.11only security fixes
    type-crashA hard crash of the interpreter, possibly with a core dump
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Apr 29, 2022
  2. sweeneyde commented on Apr 29, 2022

    @sweeneyde
    MemberAuthor

    If we're trying to emulate method_vectorcall_FASTCALL_KEYWORDS, then we're at least missing out on how method_check_args calls descr_check, which calls PyObject_TypeCheck(obj, descr->d_type). So we need one of these:

    DEOPT_IF(!PyObject_TypeCheck(PEEK(nargs), callable->d_type));
    

    or

    DEOPT_IF(!Py_IS_TYPE(PEEK(nargs), callable->d_type));
    

    I might have an off-by-one error.

    cc @Fidget-Spinner @kumaraditya303

  3. sweeneyde commented on Apr 30, 2022

    @sweeneyde
    MemberAuthor

    Marking as release blocker: it's easy to trigger but hard to reason about if you don't know about specialization, so it could create Heisenbugs, which would be unfortunate in the beta release.

  4. corona10 commented on Apr 30, 2022

    @corona10
    Member

    FYI, macOS meets the same issue as expected.

  5. sweeneyde commented on Apr 30, 2022

    @sweeneyde
    MemberAuthor

    It looks like PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS is affected as well.

  6. sweeneyde commented on Apr 30, 2022

    @sweeneyde
    MemberAuthor

    PRECALL_NO_KW_METHOD_DESCRIPTOR_O as well

  7. changed the title [-]`PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS` doesn't check types[/-] [+]specialized PRECALL opcodes don't check types[/+] on Apr 30, 2022
  8. added a commit that references this issue on Apr 30, 2022
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 fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-crashA 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