]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561) (...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 21 Mar 2025 18:48:40 +0000 (19:48 +0100)
committerGitHub <noreply@github.com>
Fri, 21 Mar 2025 18:48:40 +0000 (18:48 +0000)
The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`.
(cherry picked from commit 0de5e0c5442abddbe17481ef450e4abc992058f5)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Python/legacy_tracing.c

index 9cc3af1f5e162c14f9fe9ae8281d59e57d03ccd3..8a9ad3601a379e9d755fdd45c380a6cdc2c63d3d 100644 (file)
@@ -596,10 +596,10 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
     if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
         return -1;
     }
-    assert(tstate->interp->sys_tracing_threads >= 0);
     // needs to be decref'd outside of the lock
     PyObject *old_traceobj;
     LOCK_SETUP();
+    assert(tstate->interp->sys_tracing_threads >= 0);
     Py_ssize_t tracing_threads = setup_tracing(tstate, func, arg, &old_traceobj);
     UNLOCK_SETUP();
     Py_XDECREF(old_traceobj);