python / python/cpython

PyMemoryView_FromBuffer discards owner reference from Py_buffer

未關閉
#148,493 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-C-API type-bug
主要語言
Python
星號
77.2k
分支
36k
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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
預估耗時
一週以上
活躍度
冷清
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。