python / python/cpython

22 free-threading race conditions

未关闭
#149,816 18 条评论 9 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core topic-free-threading type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Changes

2026-05-13: Filed issue.
2026-06-08: Added new findings (16) and (86).

Bug description

I found 22 free-threading race conditions during a partial Xint Code scan of cpython. These only apply to the free-threaded build, and were all found and tested on commit 0534774a472424f6b9be2dc4ce9784384bc02401 built with ./configure --disable-gil --enable-asan on an M3 Mac.

I'm attaching a zip file with detailed writeups of each, as well as reproduction cases for 15 of the 22 issues. I don't have scripts reproducing the findings numbered 21, 36, 82, 94, 106, 115, or 124. Race conditions can be difficult to trigger, and even the scripts I provided are trying to win tight races and may not always work.

I know this is a lot. @colesbury suggested I create a combined issue to make the triage discussion easier.

Let me know if you have any questions or concerns. The issues were found and written up by an automated system, but I have put additional work into the validation and reporting. I do want to be respectful of everyone's time while helping to make Python better.

Writeups

2026-05-13: Initial writeups and test scripts: cpython-ft.zip
2026-06-08: New writeups and test scripts for (16) and (86): cpython-ft-2026-06-08.zip

Many of the scripts are expected to crash, however some of them only produce exceptions or corrupted output. You should be able to run any of the scripts with PYTHON_GIL=1 set in your environment if you want to see a baseline without the race condition.

Finding List
  • (16) Cross-interpreter syslog race
  • (17) Unlocked __init__ races with PRNG state access in Modules/_randommodule.c
  • (21) Racy EVP_MD cache overwrite leaks references in Modules/_hashopenssl.c
  • (36) Borrowed type lookup races to use-after-free in Objects/typeobject.c
  • (49) SNI callback callable race use-after-free in Modules/_ssl.c
  • (61) Racy weakref head load before incref in Objects/typeobject.c
  • (62) Concurrent kwargs growth causes heap overwrite in Objects/call.c
  • (69) Unsynchronized extra pointer dereference in len in Modules/_elementtree.c
  • (82) Non-atomic list slot memmove in shared list delete in Objects/listobject.c
  • (84) Iterator path bypasses buffered object lock in Modules/_io/bufferedio.c
  • (86) Cross-interpreter XID registry race
  • (87) Unsynchronized Element.text borrowed-pointer race in Modules/_elementtree.c
  • (89) Unsynchronized dict iteration causes borrowed-ref UAF in Modules/_pickle.c
  • (91) Racy list item borrow causes UAF in Modules/_pickle.c
  • (94) Async-exception setter races thread-state free in Python/pystate.c
  • (96) Racy GC callback list iteration in Python/gc_free_threading.c
  • (106) Immediate decref races lock-free reader in Modules/_ctypes/_ctypes.c
  • (108) Borrowed dict used after lock release in Objects/dictobject.c
  • (115) Split clear frees keys without QSBR in Objects/dictobject.c
  • (124) Stale keys race in attribute hint fastpath in Python/bytecodes.c
  • (125 wontfix) Struct reinit races with pack/unpack in Modules/_struct.c
  • (128) Borrowed list item raced before incref in Objects/bytesobject.c
  • (129) Reentrant __index__ causes released-buffer dereference in Objects/memoryobject.c
  • (132) Non-atomic exports race in memoryview.hex in Objects/memoryobject.c
CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs
  • gh-149824
  • gh-149858
  • gh-149875
  • gh-149876
  • gh-149877
  • gh-149909
  • gh-149911
  • gh-149912
  • gh-149914
  • gh-149918
  • gh-149936
  • gh-149997
  • gh-149998
  • gh-150000
  • gh-150003
  • gh-150004
  • gh-150024
  • gh-150029
  • gh-150018
  • gh-150099
  • gh-150100
  • gh-150168
  • gh-150247
  • gh-150295
  • gh-150305
  • gh-150306
  • gh-152296
  • gh-153019
  • gh-153712
  • gh-153718
  • gh-153719
  • gh-156119
  • gh-156314

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从附件 cpython-ft-2026-06-08.zip 开始,从列表中选择一个尚未勾选的发现,然后检查其中指定的 CPython 源文件和复现脚本。在 free-threaded 构建上运行该脚本,并使用 PYTHON_GIL=1 运行一次以进行比较。由于许多发现已经有链接的 PR,完成此项工作需要验证该 race,并协调一个针对性的修复或后续处理。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, python
领域
backend, testing-qa
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
18/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。