crossinterp.c: Use-after-free + leaked exception + shadowed variable
オープン
まだ誰も着手していません。
extension-modules
topic-subinterpreters
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Original gist: https://gist.github.com/devdanzin/a56b8cb579b1950b4206e8a42d6be650
Summary
Three bugs in the cross-interpreter subsystem:
- _ensure_notshareableerror (crossinterp_exceptions.h:85): Missing
returnafter_PyErr_SetRaisedExceptionstealsctxref. Falls through to code using freed pointer.- _PyXI_UnwrapNotShareableError (crossinterp_data_lookup.h:102): Exception removed from thread state via
_PyErr_GetRaisedException, then_PyXI_InitFailurefails → exception leaked, thread error indicator cleared.- _pop_preserved (crossinterp.c:2968): Inner
_PyXI_namespace *xidatashadows outer.goto errorcleanup checks outer (NULL) variable → inner allocation leaked.Reproducer (ref leak)
import _interpchannels as ch, sys cid = ch.create() before = sys.gettotalrefcount() for i in range(10000): try: ch.send(cid, lambda: None, blocking=False) except Exception: pass after = sys.gettotalrefcount() ch.destroy(cid) print(f"Leaked {after - before} refs (~{(after-before)//10000}/send)")
The third issue is already fixed by https://github.com/python/cpython/pull/147999
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-153665
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
crossinterp_exceptions.h:85、crossinterp_data_lookup.h:102、crossinterp.c:2968 から始め、次に提供された _interpchannels の参照カウント再現プログラムを CPython main 上で実行します。shadowed-variable の問題はすでに修正済みと報告されているため、既存の PR を確認してください。残る例外と参照管理の 2 つのバグが、リークや use-after-free の動作なしに修正されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100