]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Fix data race in `_Py_IsImmortal` (#118261)
authormpage <mpage@meta.com>
Thu, 25 Apr 2024 15:31:57 +0000 (08:31 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2024 15:31:57 +0000 (11:31 -0400)
The load of `ob_ref_local races with stores. Using a relaxed load is
sufficient; stores to the field are relaxed.

Include/object.h
Tools/tsan/suppressions_free_threading.txt

index ffcacf1a3ef4ed9a1e76e9c2480bcfba0bfd152e..5aaf11c5194f0e3f1eb1d1396c36bd66548d1554 100644 (file)
@@ -349,7 +349,8 @@ static inline Py_ssize_t Py_SIZE(PyObject *ob) {
 static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
 {
 #if defined(Py_GIL_DISABLED)
-    return (op->ob_ref_local == _Py_IMMORTAL_REFCNT_LOCAL);
+    return (_Py_atomic_load_uint32_relaxed(&op->ob_ref_local) ==
+            _Py_IMMORTAL_REFCNT_LOCAL);
 #elif SIZEOF_VOID_P > 4
     return (_Py_CAST(PY_INT32_T, op->ob_refcnt) < 0);
 #else
index 1408103ba80f96f02314ae9e2021550cca86fb19..6ceb275925c5e196a0f81c1c63ed6c50869bccfa 100644 (file)
@@ -14,7 +14,6 @@ race:set_allocator_unlocked
 race:_add_to_weak_set
 race:_in_weak_set
 race:_mi_heap_delayed_free_partial
-race:_Py_IsImmortal
 race:_Py_IsOwnedByCurrentThread
 race:_PyEval_EvalFrameDefault
 race:_PyFunction_SetVersion