python / python/cpython

PyMemoryView_FromBuffer discards owner reference from Py_buffer

オープン
#148,493 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core topic-C-API type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

https://github.com/python/cpython/blob/0274d8304e5eec23de100d827eb4da06ab7fd8aa/Objects/memoryobject.c#L769-L788

This means that if you use PyMemoryView_FromBuffer with a buffer that requires an owner to be kept alive, you get a UAF hazard here.

This is not mentioned in the documentation: https://docs.python.org/3/c-api/memoryview.html#c.PyMemoryView_FromBuffer

An extremely cursory didn't find any vulnerable callers within CPython itself, however this was discovered in the process of implementing https://github.com/PyO3/pyo3/pull/5937 where it definitely would have been an issue.

It seems like there's two possible choices here:

  • Change this to keep owner around -- potentially breaks existing callers?
  • Document this, and introduce a new API with clearer semantics here.
CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Objects/memoryobject.c のリンクされた PyMemoryView_FromBuffer 実装から始め、PyMemoryView_FromBuffer C-API のドキュメントを読んでください。PyO3 の pull request #5937 を確認して owner のライフタイム要件を理解し、その後、owner を保持する場合と新しい API を導入する場合の互換性への影響を比較してください。ownership のセマンティクスが決定され、文書化され、適切な CPython テストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
api
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。