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

Ouverte
#14,202 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
52/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
cpp
Domaine
backend, networking

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
C++
Étoiles
2k
Forks
903
Merge moyen
4 j 4 h
PR mergées (30 j)
135

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/trafficserver

Toutes les issues de apache/trafficserver

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.