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

未关闭
#14,219 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
135

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/trafficserver 的其他 Issue

查看 apache/trafficserver 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。