MIOBufferAccessor::reader_for(IOBufferReader *) dereferences a null reader and leaves VIOs pointing at freed readers

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

メンテナーはふだん 2 日以内に返信

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

評価

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

調査の方向性

Start with IOBuffer.cc around MIOBufferAccessor::reader_for(IOBufferReader *), then trace MIOBuffer::dealloc_reader() and the VIO get_reader()/get_writer() accessors. Check the cited CacheVC.cc call and the related guards in UnixNetVConnection::do_io_write() and PluginVC::do_io_write(). Done means null readers are handled safely and the reader lifetime and accessor ownership behavior are defined and covered.

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

説明

Bug IOBuffer

VIO::set_reader() is buffer.reader_for(reader), which is implemented at IOBuffer.cc#L1089-L1097:

if (entry == areader) {
  return;
}
mbuf  = areader->mbuf;
entry = areader;

There are two problems:

  1. Null reader. reader_for(nullptr) dereferences null unless the accessor's current reader is already null. Callers have to know this. UnixNetVConnection::do_io_write() and PluginVC::do_io_write() guard the call, and INKVConnInternal::do_io_write() crashed this way in #13395. CacheVC::do_io_write() still calls vio.set_reader(abuf) without a check (CacheVC.cc#L209), so a do_io_write(c, 0, nullptr) on a cache write VC that already has a reader would crash the same way.
  2. No back-pointer. Unlike reader_for(MIOBuffer *), which allocates the reader through alloc_accessor(this), this overload never sets areader->accessor. MIOBuffer::dealloc_reader() clears the accessor that a reader points back to (IOBuffer.cc#L1047-L1050). Without the back-pointer, freeing the reader or its buffer leaves the VIO holding dangling mbuf/entry pointers, which are reachable via VIO::get_reader()/get_writer() and TSVIOReaderGet()/TSVIOBufferGet(). This is harmless as long as nothing touches the VIO after its operation ends, but it is not enforced anywhere.

Suggested fix: make reader_for(nullptr) clear the accessor rather than dereference null. For the second problem, either register the accessor on the reader (the reader belongs to the VIO's producer, so this needs a defined owner) or document that the reader must outlive any use of the VIO.


generated with Claude Opus 5.5 by Josiah VanderZee

主要言語
C++
スター
2k
フォーク
903
平均マージ
4日 4時間
マージ済み PR(30日)
135

環境構築

はじめの一歩

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

apache/trafficserver のほかの issue

apache/trafficserver の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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