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

Offen
#14,219 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cpp
Bereich
api, backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
C++
Sterne
2k
Forks
903
Ø Merge
4 T. 4 Std.
Gemergte PRs (30 T.)
135

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus apache/trafficserver

Alle Issues in apache/trafficserver

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.