crossinterp.c: Use-after-free + leaked exception + shadowed variable
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với crossinterp_exceptions.h:85, crossinterp_data_lookup.h:102 và crossinterp.c:2968, sau đó chạy trình tái hiện đếm tham chiếu _interpchannels được cung cấp trên CPython main. Kiểm tra các PR hiện có, vì vấn đề biến bị che khuất đã được báo cáo là đã sửa; được xem là hoàn tất khi hai lỗi còn lại về exception và quản lý tham chiếu được sửa mà không có rò rỉ hoặc hành vi use-after-free.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100