PluginVC::process_write_side reads the peer's read VIO before locking it

Offen
#14,202 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
52/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
cpp
Bereich
backend, networking

Rechercherichtung

Read src/proxy/PluginVC.cc, especially process_write_side() around lines 517–590 and the VIO setup in do_io_read() around lines 266–273. Check how the peer read VIO mutex protects op, closed, shutdown, nbytes, and ndone, then verify the transfer size is calculated under that lock. Done means the peer state is rechecked after locking and the read completion behavior remains correct.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Bug PluginVC

PluginVC::process_write_side() moves data from this side's write VIO into the other side's read VIO. The other side's read VIO is owned by a different continuation, so its fields are protected by that VIO's mutex, which the function try-locks at PluginVC.cc#L542. Before taking that lock, it already reads the peer's VIO state:

  • other_side->read_state.vio.op (PluginVC.cc#L517)
  • other_side->read_state.vio.ntodo(), i.e. nbytes and ndone (PluginVC.cc#L532). The result caps act_on and is reused after the lock is taken.

Those fields are written by the peer's consumer under its own mutex, not the PluginVC core mutex: do_io_read() sets them (PluginVC.cc#L266-L273), and the consumer may change nbytes at any time. The comments there say op is "set last" so that process_*_side can read it as an activity flag. That ordering is not guaranteed for plain fields, so the unlocked reads are data races when the peer's consumer runs on another thread, such as an intercept or TSHttpConnect plugin. In that case, an nbytes lowered concurrently by the peer can be overrun, because the transfer size was computed from the pre-lock value. The peer then ends up with ndone > nbytes and never gets VC_EVENT_READ_COMPLETE from the ntodo() == 0 check at PluginVC.cc#L590.

process_read_side() doesn't have this problem: it takes the peer write VIO lock and then calls other_side->process_write_side(), which re-reads everything.

Suggested fix: after the try-lock succeeds, re-check op/closed/shutdown and compute other_ntodo. Only the mutex pointer itself has to be read before locking.


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.