]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-117657: Fix TSan reported data race on ioctl_works (GH-120175) (#120654)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 17 Jun 2024 17:52:49 +0000 (19:52 +0200)
committerGitHub <noreply@github.com>
Mon, 17 Jun 2024 17:52:49 +0000 (17:52 +0000)
(cherry picked from commit 460cc9e14e221c53c0038a847bfd411fe184ebf3)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Python/fileutils.c
Tools/tsan/suppressions_free_threading.txt

index e6a5391a3a28b56143373af3c5de3f307ef5f426..c9ae1b3f54e1675da32582cfc46136fec6f87c8e 100644 (file)
@@ -1502,7 +1502,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
 #else
 
 #if defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX)
-    if (ioctl_works != 0 && raise != 0) {
+    if (raise != 0 && _Py_atomic_load_int_relaxed(&ioctl_works) != 0) {
         /* fast-path: ioctl() only requires one syscall */
         /* caveat: raise=0 is an indicator that we must be async-signal-safe
          * thus avoid using ioctl() so we skip the fast-path. */
@@ -1512,7 +1512,9 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
             request = FIOCLEX;
         err = ioctl(fd, request, NULL);
         if (!err) {
-            ioctl_works = 1;
+            if (_Py_atomic_load_int_relaxed(&ioctl_works) == -1) {
+                _Py_atomic_store_int_relaxed(&ioctl_works, 1);
+            }
             return 0;
         }
 
@@ -1539,7 +1541,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
                with EACCES. While FIOCLEX is safe operation it may be
                unavailable because ioctl was denied altogether.
                This can be the case on Android. */
-            ioctl_works = 0;
+            _Py_atomic_store_int_relaxed(&ioctl_works, 0);
         }
         /* fallback to fcntl() if ioctl() does not work */
     }
index 4c8b0b8abd2963db0c8627119d017609b4858196..b86c8fce11f57ea6bf57e44ce5d0dd4d2f176ddc 100644 (file)
@@ -35,7 +35,6 @@ race_top:new_reference
 race_top:set_contains_key
 # https://gist.github.com/colesbury/d13d033f413b4ad07929d044bed86c35
 race_top:set_discard_entry
-race_top:set_inheritable
 race_top:_PyDict_CheckConsistency
 race_top:_Py_dict_lookup_threadsafe
 race_top:_multiprocessing_SemLock_acquire_impl