Skip to content

Evil call_soon may cause OOB in future_schedule_callbacks #125969

Closed

Description

@picnixz

Crash report

Bug description:

In future_schedule_callbacks, the length of the callback list is assumed to be constant, but an evil call_soon can make it change.

PoC:

import asyncio
called_on_fut_callback0 = False

pad = lambda: ...

def evil_call_soon(*args, **kwargs):
    global called_on_fut_callback0
    if called_on_fut_callback0:
        # Called when handling fut->fut_callbacks[0]
        # and mutates the length fut->fut_callbacks.
        fut.remove_done_callback(int)
        fut.remove_done_callback(pad)
    else:
        called_on_fut_callback0 = True

fake_event_loop = lambda: ...
fake_event_loop.call_soon = evil_call_soon
fake_event_loop.get_debug = lambda: False  # suppress traceback
fut = asyncio.Future(loop=fake_event_loop)
fut.add_done_callback(str)  # sets fut->fut_callback0
fut.add_done_callback(int)  # sets fut->fut_callbacks[0]
fut.add_done_callback(pad)  # sets fut->fut_callbacks[1]
fut.add_done_callback(pad)  # sets fut->fut_callbacks[2]
fut.set_result("boom")

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    type-crash
    on Oct 25, 2024
  2. self-assigned this
    on Oct 25, 2024
  3. added
    3.12
    3.13
    3.14
    on Oct 25, 2024
  4. added a commit that references this issue on Oct 25, 2024
  5. added 2 commits that reference this issue on Oct 25, 2024
  6. added 2 commits that reference this issue on Oct 25, 2024
  7. kumaraditya303 commented on Oct 25, 2024

    @kumaraditya303
    Contributor

    thanks

  8. moved this from Todo to Done in asyncioon Oct 25, 2024
  9. added a commit that references this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.123.133.14topic-asynciotype-crash

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions