Repository navigation
Description
ObjHeader::PassiveGetSyncBlock() can combine a retired sync-table base with an index allocated from a newer table
generation. At the second and later table growths, the unchecked subscript can read beyond the retired allocation and
use a nonnull value as a SyncBlock*. Ordinary CoreCLR monitor inflation and object hash-code paths can reach this in
supported Release configurations; it is not restricted to diagnostics or interop.
This finding is from source analysis and has not been dynamically reproduced. The minimal second-growth case reads a
pointer beginning one entry past a still-live old table. A reader stalled across additional slot assignments can address
farther beyond it. The ordinary cooperative/GC-notrigger schedule does not permit the old table to be reclaimed during
the lookup, so this is not a claimed use-after-free. No same-root-cause duplicate search hit was confirmed.
Evidence
src\coreclr\vm\syncblk.h:894-897-PassiveGetSyncBlock()evaluates a plain global table base and a
barrier-free header-index load in one unchecked subscript, with no lock, capacity snapshot, or retry.src\coreclr\vm\syncblk.cpp:637-678-Grow()allocates later tables at exactly their logical size, chains the old
table for deferred reclamation, copies its entries, and interlocked-publishes the larger base.src\coreclr\vm\syncblk.cpp:704-743- when the next index equals the logical size, slot allocation grows the table
but returns that pre-growth boundary index.src\coreclr\vm\syncblk.cpp:1557-1646- the first passive lookup is outside the cache lock; a writer can grow,
initialize the new slot and block, and then publish the object's index while holding that lock.src\coreclr\vm\syncblk.cpp:447-465- startup allocates 251 entries for logical size 250, so the first boundary is
physically in bounds; the exact 500-entry table created by the first growth makes index 500 at the second growth the
first unambiguous out-of-bounds boundary.src\coreclr\vm\syncblk.cpp:652-656,845-865- retired arrays are retained until the GC has exclusive access, ruling
out reclamation during the concrete cooperative/no-GC reader interval.
Feasible interleaving
- Reader A enters an ordinary monitor/hash passive lookup for a rooted victim and captures exact-size table T with
capacity 500, then is descheduled before loading the victim's header index. - Writer B holds the sync-block cache lock, grows to T2, initializes T2[500] and its
SyncBlock, then publishes index
500 in the victim's header. - Reader A resumes, observes index 500, and evaluates
T[500].m_SyncBlock, whose pointer field begins immediately
beyond T's allocation. - A null/garbage value can cause a miss or access violation; a nonnull value can be dereferenced as a
SyncBlock*,
causing incorrect monitor/hash behavior, a crash, or in-process memory corruption in a Release build.
Expected behavior
An observed sync-block index must be resolved through that index's table generation or a newer one, and a nonnull
entry pointer must publish a completely initialized SyncBlock. A captured table generation must remain alive for the
whole no-GC lookup interval.
Actual behavior
The reader combines an ordinary table-base load with a barrier-free header load and does not validate their generation.
Writer serialization and interlocked publication do not refresh a base that the reader already captured. Retired-table
lifetime prevents a dangling pointer but does not make newer indices valid in the old allocation.
Suggested fix
Keep readers lock-free and define three explicit publication edges. First acquire-load and decode the header index into
a local; only then acquire-load the current global table through a common accessor. Acquire-load the selected
m_SyncBlock, paired with a release store after the block and all initial lifetime metadata are initialized. For an
already-existing index, move SetPrecious() before publishing the nonnull entry because no new header SetIndex()
publication occurs.
Retain the interlocked table exchange and header CAS, the existing writer cache lock, monotonic table growth, and
stop-the-world retirement. Preserve DAC/cDAC layout and use a stopped-target DAC accessor. Audit direct
g_pSyncTable/entry users so compiler CSE or a bypass cannot reintroduce the old-base/new-index combination.
Safety considerations
The ordinary reader and writer schedule is cooperative and GC-notrigger. A stalled reader blocks EE suspension, while
old tables are freed during an exclusive GC scan, so the concrete bug is an out-of-bounds read from a live retired
allocation rather than use-after-free. The repair must not retain a table or entry across a safepoint or mode transition.
Adding the cache Crst to the reader is not recommended: the helper is hot, can be called while that non-reentrant lock is
already held, and appears in NOTHROW/GC-notrigger paths. The lock-free repair adds no allocation, callback, reentrancy,
lock-order, or shutdown transition. Acquire loads are expected to be cheap on x64 but can add ldar costs on Arm64;
measure the final placement. Do not rely on Arm64 address dependencies, incidental compiler ordering, a bounds check
against an independently loaded size, or one spare allocation entry as the correctness contract.
Suggested validation
In a test runtime, add a bounded native scheduling hook between base and index loads. Fill an exact-size grown table,
hold a cooperative reader at the hook, allocate a rooted hash-coded victim at the second-growth boundary, and verify
the captured capacity/index without deliberately consuming garbage. A guard page or allocator red zone after the old
table can make the pre-fix overread deterministic.
Also test publication into an already-existing index, and stress monitor enter/exit, recursion/timeouts, and hash-code
stability during repeated growth. Run optimized x64 and Arm64 coverage on Windows and Unix, inspect emitted load order
and acquire operations, and run Arm64 stress without injected delays. Exercise server/background GC, reuse, and
post-reader reclamation, plus COM/diagnostics compatibility. Measure monitor/hash microbenchmarks on Arm64. No build,
test, disassembly inspection, or dynamic reproduction was performed while preparing this draft.
Reviewer synthesis
Both reviewers validated the missing table-generation invariant, selected vm, found no confirmed duplicate, and
recommended approval. Reviewer A rated confidence 9/10 and proposed separate header, table, and entry publication
edges. Reviewer B rated 7/10, correctly established that the ordinary schedule cannot free the retired table, and
proposed a smaller header-acquire repair.
The selected synthesis keeps Reviewer B's index-before-base requirement and lifetime correction but adopts Reviewer
A's complete three-edge protocol. A header acquire alone does not publish a later table copy when the index predates
that growth, and it does not publish a SyncBlock installed later into an existing index without another SetIndex().
The minimal overrun is one entry at the second growth; longer stalls can produce farther addresses, but no speculative
maximum or exploitability claim is needed.
Note
This issue draft was generated with GitHub Copilot and requires maintainer review before filing.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Sep 19, 2026
Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.
Order sync-table lookups and SyncBlock publication (#135179)