python / python/cpython

Dialog about overrun of a stack-based buffer on Windows Server 2022 (caused by `asyncio` / `socket`)

Đang mở
#145,899 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

extension-modules OS-windows topic-socket type-crash
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ả

Crash report

What happened?

On Windows Server 2022, when exiting a Python process, we sporadically get a dialog with the title "python.exe - System Error", which reads "The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application."

We do not get this error with Windows Server 2019.

The issue is very sporadically. Even with the following reproducers, we only experience the issue every 1,000 to 100,000 runs on our systems.

Our initial reproducer was:

import asyncio  
async def f():  
    pass
asyncio.run(f())

We could narrow it down further to:

import socket
socket.socketpair()

(The issue does also occur if I close the sockets returned from socketpair.)

The issue can also be reproduced with the following snippet extracted from socket.socketpair():

import socket

l = socket.socket()
l.bind(("127.0.0.1",0))
l.listen()

c = socket.socket()
c.setblocking(False)
try:
    c.connect(l.getsockname())
except BlockingIOError:
    pass

Setting the socket to unblocking seems to be essential. I could not reproduce the issue without setting it to unblocking.

Further, calling os._exit() prevents the issue. I digged a little further and found that not calling WSACleanup() in os_cleanup() in socketmodule.c prevents the issue.

CPython versions tested on:

3.11, 3.12, 3.13, 3.14

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong socketmodule.c tại os_cleanup(), tập trung vào lệnh gọi WSACleanup(). Chạy lặp lại trình tái hiện tối thiểu sử dụng socketpair() hoặc socket không chặn trên Windows Server 2022 và so sánh hành vi với Windows Server 2019. Hoàn tất khi đã xác định và sửa đường dẫn shutdown để hộp thoại stack-buffer-overrun không còn xuất hiện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
networking, operating-systems
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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.