shadowaead_2022: data race between clientConn.writeRequest and Close

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go
領域
networking

調査の方向性

Start with shadowaead_2022.clientConn, especially writeRequest, Write, and Close, and reproduce the report using the described rejected-key client/server setup under Go's -race flag. Ensure the lazy request state is synchronized between the first Write and Close, then verify the reproduction no longer reports a race.

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

説明

sing-shadowsocks2 (as used by sing-box v1.13.12), go 1.26, -race

shadowaead_2022.clientConn sends its request header lazily on the first Write (writeRequest), which initializes connection state. Close, typically called from the other copy direction when the server drops the connection, reads that state without synchronization:

WARNING: DATA RACE
Read by goroutine A:
  github.com/sagernet/sing-shadowsocks2/shadowaead_2022.(*clientConn).Close()
  github.com/sagernet/sing/common.Close()
  github.com/sagernet/sing-box/route.(*ConnectionManager).connectionCopy()

Previous write by goroutine B:
  github.com/sagernet/sing-shadowsocks2/shadowaead_2022.(*clientConn).writeRequest()
  github.com/sagernet/sing-shadowsocks2/shadowaead_2022.(*clientConn).Write()
  github.com/sagernet/sing/common/bufio.copyExtendedWithPool()
  github.com/sagernet/sing-box/route.(*ConnectionManager).connectionCopy()

Reproduce: a Shadowsocks 2022 client whose key the server rejects. The server closes the connection right away, so the download direction ends and closes the conn while the upload direction is still in its first Write. It triggers reliably under -race with an in-process sing-box SS2022 inbound and a client configured with a different user key.

Suggested fix: guard the lazily initialized fields that writeRequest sets and Close reads (e.g. a mutex, or an atomic "request written" state checked by Close). Happy to send a PR.

主要言語
Go
スター
23
フォーク
37
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

似ている issue

Go の issue をもっと見る

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

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