Skip to content

Commit abe64a3

Browse files
[3.13] gh-126080: fix UAF on task->task_context in task_call_step_soon due to an evil loop.__getattribute__ (GH-126120) (#126250)
gh-126080: fix UAF on `task->task_context` in `task_call_step_soon` due to an evil `loop.__getattribute__` (GH-126120) (cherry picked from commit 0e86655) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 588da2e commit abe64a3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a use-after-free crash on :class:`asyncio.Task` objects for which the
2+
underlying event loop implements an evil :meth:`~object.__getattribute__`.
3+
Reported by Nico-Posada. Patch by Bénédikt Tran.

Modules/_asynciomodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,11 @@ task_call_step_soon(asyncio_state *state, TaskObj *task, PyObject *arg)
26782678
return -1;
26792679
}
26802680

2681-
int ret = call_soon(state, task->task_loop, cb, NULL, task->task_context);
2681+
// Beware: An evil call_soon could alter task_context.
2682+
// See: https://github.com/python/cpython/issues/126080.
2683+
PyObject *task_context = Py_NewRef(task->task_context);
2684+
int ret = call_soon(state, task->task_loop, cb, NULL, task_context);
2685+
Py_DECREF(task_context);
26822686
Py_DECREF(cb);
26832687
return ret;
26842688
}

0 commit comments

Comments
 (0)