
Proof-of-concept for CVE-2026-118383, an unauthenticated MongoDB use-after-free in replication catch-up, with wire-protocol exploit scripts, a gdb crash oracle, and fixed-version controls.
| CVE | CVE-2026-118383 |
| Component | MongoDB server, replication (ReplicationCoordinatorImpl) |
| Affected | 8.0.x before 8.0.37 (8.0.34 tested); 8.2 builds before the backport (8.2.12 tested) |
| Fixed in | 8.0.37 (23dfc54219, 6111165c32) |
| CWE | CWE-416 — use-after-free |
| Trigger | Unauthenticated readConcern.afterOpTime waiter poisoning + primary catch-up abort |
| Impact | mongod crash / memory corruption in the replication coordinator |
A ReplicationCoordinatorImpl::CatchupState object can free itself while one
of its own methods is still running. The completion callback registered for the
primary catch-up waiter captures a raw this, ignores the completion status,
and calls abort_inlock(kSucceeded) from inside abort_inlock(). The inner
call resets _repl->_catchupState and destroys the object; the outer frame then
continues to read and write through the freed pointer.
The waiter can be kept unfulfilled by an unauthenticated client. Two
readConcern.afterOpTime waiters with adversarial opTime terms create an
ordering cycle in std::multimap<OpTime, Waiter>, so the real catch-up waiter
is never reached by setValueIf_inlock(). The next heartbeat concludes
"already caught up" and aborts catch-up, which destroys the unfulfilled waiter
and re-enters abort_inlock().
Two server fixes shipped in 8.0.37:
23dfc542199ab3b88d6a9420b6cd3f125a897620 — SERVER-138175. CatchupState
becomes enable_shared_from_this, _catchupState becomes a shared_ptr, and
the callback holds a weak_ptr, returns on non-OK status, and only concludes
catch-up if it still owns the current state.6111165c32bfc74f197e2dfeb9480d0b52154d68 — SERVER-138119. Rejects
client-supplied readConcern.afterOpTime unless the client holds
ActionType::internal.# Vulnerable 8.0.34: deterministic double abort (UAF fingerprint)
./run.sh assisted
# Fixed 8.0.37: same attack, no double abort
MONGO_IMAGE=docker.io/mongodb/mongodb-community-server:8.0.37-ubi9 \
./run.sh assisted
# Unauthenticated afterOpTime acceptance, vulnerable vs fixed
AUTH=1 ./run.sh control
AUTH=1 MONGO_IMAGE=docker.io/mongodb/mongodb-community-server:8.0.37-ubi9 \
./run.sh control
run.sh <mode> tears down any previous replica set, starts three members,
runs the PoC, captures the report and server logs under results/, and tears
the set down again. A non-zero exit means the run did not reach an expected
verdict. Use ./run.sh up and ./run.sh poc <mode> to keep a set running for
inspection.
Requirements: Podman, mongosh (only used inside the MongoDB images), and
Python 3.10+ if poc.py is run directly. The PoC itself has no third-party
dependencies; mongo_wire.py implements BSON and OP_MSG from the standard
library.
Vulnerable code in src/mongo/db/repl/replication_coordinator_impl.cpp:
void ReplicationCoordinatorImpl::CatchupState::abort_inlock(
PrimaryCatchUpConclusionReason reason) {
...
if (reason != PrimaryCatchUpConclusionReason::kSucceeded && _waiter) {
_repl->_lastAppliedOpTimeWaiterList.remove_inlock(_waiter);
_waiter.reset(); // may synchronously run targetOpTimeCB
}
_repl->_enterDrainMode_inlock();
_repl->_catchupState.reset(); // destroys `this`
}
auto targetOpTimeCB = [this](Status status) {
// status is ignored
const auto myLastApplied = _repl->_getMyLastAppliedOpTime_inlock();
if (_targetOpTime <= myLastApplied) {
...
abort_inlock(PrimaryCatchUpConclusionReason::kSucceeded); // re-enters
}
};
Three conditions make the re-entry fatal:
_waiter.lastApplied >= _targetOpTime.kSucceeded destroys the waiter. The
synchronous callback observes that the target is already applied and calls
abort_inlock(kSucceeded) again.The second condition is reachable because OpTime::operator< is not a strict
weak ordering when either side carries the legacy/uninitialized term -1:
inline bool operator<(const OpTime& rhs) const {
if (_term == kUninitializedTerm || rhs._term == kUninitializedTerm)
return _timestamp < rhs._timestamp; // timestamp only
return std::tie(_term, _timestamp) < std::tie(rhs._term, rhs._timestamp); // term first
}
Plant two waiters in this order:
W1 = {ts: applied + 1s, term: -1} — term omitted on the wireW2 = {ts: Timestamp(1, 1), term: 2^40}With W1 inserted first, the multimap order becomes W2, W1, C (where C is
the catch-up waiter): W2 < W1 by timestamp, W1 < C by timestamp, and
C < W2 by term. Iteration in setValueIf_inlock() starts at W2, whose key
compares greater than any real lastApplied, so the loop stops before C. The
poisoned ordering survives until the next heartbeat aborts catch-up.
readConcern is a generic command argument, and waitForReadConcern runs
before command dispatch. The deprecated afterOpTime field was accepted from
any connection, including unauthenticated clients and commands that require no
privileges (ping, hello). The fixed jstest
jstests/auth/after_op_time_requires_internal.js checks exactly that case.
The waiter-poisoning primitive needs no credentials. The reproduction also drives the election that turns the poison into catch-up state; on an auth-enabled deployment that step requires replica-set control. The security boundary crossed by SERVER-138119 is that any connection could register waiters on a secondary's last-applied list.
checkAuthForAfterOpTime() asks for ActionType::internal on the cluster. When
security.authorization is disabled, that action is effectively granted to
every client, so even 8.0.37 accepts afterOpTime without a keyFile. The auth
fix is only observable on an auth-enabled deployment. AUTH=1 starts every
member with a shared keyFile, bootstraps an admin user through the localhost
exception, and leaves the attacker connection unauthenticated.
AUTH=1 supports control only. assisted and natural need the
unauthenticated test commands used to hold the applier and are run with auth
disabled.
pauseBatchApplicationAfterWritingOplogEntries on n2, so its oplog is
current (it can win votes) while lastApplied lags (so primary catch-up
registers a waiter). Both poison waiters are planted through unauthenticated
ping commands with readConcern.afterOpTime. This isolates the UAF logic
from timing noise.DOUBLE_ABORT_UAF with N2_CPUS=0.25, six writers, and an 8-second backlog,
but assisted is the reliable mode.ping with readConcern.afterOpTime and a
short maxTimeMS. Vulnerable builds accept the read concern and the command
waits (code 50, timeout). Fixed builds with auth reject it immediately with
code 13 (Unauthorized).