python / python/cpython

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

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

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

extension-modules OS-windows topic-socket type-crash
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

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

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

はじめの一歩

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

調査の方向性

socketmodule.c の os_cleanup() から開始し、WSACleanup() の呼び出しに注目してください。Windows Server 2022 で socketpair() または非ブロッキングソケットを使った最小の再現手順を繰り返し実行し、Windows Server 2019 と動作を比較してください。stack-buffer-overrun ダイアログが表示されなくなるように shutdown パスを特定して修正できれば完了です。

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

評価

技術スタック
python
領域
networking, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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