UnixNetProcessor::connect_re allocates from another thread's freelist

Aperta
#14,196 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Start with the cited allocation and affinity paths in src/iocore/net/UnixNetProcessor.cc, then read the ownership rule in include/iocore/eventsystem/Thread.h and the cache operations in include/iocore/eventsystem/ProxyAllocator.h. Trace how THREAD_ALLOC_INIT behaves when the selected thread differs from the calling thread, including the TSNetConnect example in src/api/InkAPI.cc. Done means preventing access to another thread’s ProxyAllocator cache and handling the reported missing mutex check safely.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Network Threads TS API

UnixNetProcessor::connect_re chooses the thread the new connection will run on with eventProcessor.assign_affinity_by_type(cont, opt.etype) (UnixNetProcessor.cc#L192-L193). It then allocates the NetVC from that thread's per-thread freelist, THREAD_ALLOC_INIT(netVCAllocator, t) (UnixNetProcessor.cc#L316).

assign_affinity_by_type returns the calling thread only if it already has the requested event type. Otherwise it returns the continuation's affinity thread or a newly assigned thread of that type (UnixEventProcessor.cc#L662-L677). The allocators have two layers, and only one of them is safe to share between threads. The global ClassAllocator freelists are lock-free and safe to use from any thread (ink_queue.cc#L206). In front of each global allocator, every Thread keeps a ProxyAllocator cache. That cache is a plain singly linked list, popped by thread_alloc and pushed by THREAD_FREE with no atomics or lock (ProxyAllocator.h#L54-L60, #L106-L119). It avoids the CAS on the hot path, and that is only safe because a single thread owns it. Thread.h states the rule: the Thread passed to the macros MUST be the calling OS thread's own Thread (Thread.h#L175-L177). THREAD_ALLOC_INIT only reaches the lock-free global list when that cache is empty. So a connect started from a thread that isn't ET_NET pops another thread's ProxyAllocator cache while that thread may be pushing to or popping from it. One example is a plugin calling TSNetConnect from an ET_TASK continuation (InkAPI.cc#L6774). This is a data race that can corrupt that cache, for example handing the same NetVC out twice.

assign_affinity_by_type also dereferences cont->mutex->thread_holding without a check (L664). It crashes if the caller doesn't hold the continuation's mutex.

A fix is to allocate from the current thread, or from the global allocator, when t != this_ethread().


generated with Claude Opus 5.5 by Josiah VanderZee

Lingua principale
C++
Stelle
2k
Fork
903
Merge medio
4g 4h
PR unite (30g)
135

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/trafficserver

Tutte le issue di apache/trafficserver

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.