]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45262, asyncio: Fix cache of the running loop holder (GH-28796)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 7 Oct 2021 23:14:04 +0000 (16:14 -0700)
committerGitHub <noreply@github.com>
Thu, 7 Oct 2021 23:14:04 +0000 (16:14 -0700)
Prevent use-after-free of running loop holder via cache.
(cherry picked from commit 392a89835371baa0fc4bf79ae479abb80661f57d)

Co-authored-by: Matthias Reichl <github@hias.horus.com>
Misc/NEWS.d/next/Library/2021-10-07-14-04-10.bpo-45262.HqF71Z.rst [new file with mode: 0644]
Modules/_asynciomodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-10-07-14-04-10.bpo-45262.HqF71Z.rst b/Misc/NEWS.d/next/Library/2021-10-07-14-04-10.bpo-45262.HqF71Z.rst
new file mode 100644 (file)
index 0000000..4cd949f
--- /dev/null
@@ -0,0 +1 @@
+Prevent use-after-free in asyncio. Make sure the cached running loop holder gets cleared on dealloc to prevent use-after-free in get_running_loop
\ No newline at end of file
index b615c48c431828696af8cf7628429265c844dfba..4457d7bd49e2320dfeefe05d8d900c861a36ed5c 100644 (file)
@@ -3258,6 +3258,9 @@ new_running_loop_holder(PyObject *loop)
 static void
 PyRunningLoopHolder_tp_dealloc(PyRunningLoopHolder *rl)
 {
+    if (cached_running_holder == (PyObject *)rl) {
+        cached_running_holder = NULL;
+    }
     Py_CLEAR(rl->rl_loop);
     PyObject_Free(rl);
 }