-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Queryable Encryption
-
Server Security
-
Fully Compatible
-
ALL
-
v9.0, v8.3, v8.0, v7.0, v8.2
-
Server Security 2026-07-17, Server Security 2026-07-31, Server Security 2026-08-14, Server Security 2026-08-28, Server Security 2026-09-11, Server Security 2026-10-23, Server Security 2026-11-06, Server Security 2026-11-20
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Security Context
See SECBUG-1461 for problem description, security impact, preconditions, reproduction steps, and severity rationale. A verified Docker-based PoC is included in that ticket.
Root Cause
The bug is a type-width mismatch in src/mongo/crypto/fle_tags.cpp::readTags(). Three lines interact to produce the exploit:
Line 148 — accumulator declared as uint32_t
uint32_t totalTagCount = 0;
FLEEdgeCountInfo::count (fle_crypto_types.h:92) is uint64_t. The accumulation loop silently truncates each 64-bit count to 32 bits on assignment.
Lines 150-155 — unguarded accumulation wraps to zero
for (const auto& countInfoSet : countInfoSets) { for (const auto& countInfo : countInfoSet) { totalTagCount += countInfo.count; // truncates uint64_t → uint32_t } }
An attacker-controlled ESC null-anchor document with cpos = 2^32 causes countInfo.count = 2^32. Adding 2^32 to a zero uint32_t wraps to exactly 0.
Lines 156-164 — limit check and reserve use the wrapped zero, generateTags uses the original count
verifyTagsWillFit(totalTagCount, memoryLimit); // verifyTagsWillFit(0, 14MB) — trivially passes binaryTags.reserve(totalTagCount); // reserve(0) — no allocation for (const auto& countInfoSet : countInfoSets) { for (const auto& countInfo : countInfoSet) { generateTags(countInfo.count, countInfo.edc.value(), binaryTags); // called with 2^32 } }
generateTags() loops from 1 to numInserts inclusive (fle_tags.cpp:85). With numInserts = 2^32, it calls binaryTags.push_back() approximately four billion times. Each PrfBlock is 32 bytes; four billion entries require ~128 GB. The process consumes all available CPU and memory until the host OOM killer terminates it or the server becomes unavailable.The default internalQueryFLERewriteMemoryLimit is 14 MB (query_integration_knobs.idl:71). verifyTagsWillFit is designed to enforce this limit but receives 0 instead of the true tag count, so sizeArrayElementsMemory(0) = 0 ≤ 14 MB passes unconditionally.
Proposed Fix
Change the accumulator to uint64_t to match the width of countInfo.count:
// fle_tags.cpp:148 — before uint32_t totalTagCount = 0; // after uint64_t totalTagCount = 0;
This is sufficient to prevent the wrap-to-zero. verifyTagsWillFit already takes size_t (64-bit on all supported platforms) so the widened value flows through correctly.
As a secondary defense, add an overflow uassert in the accumulation loop:
for (const auto& countInfoSet : countInfoSets) { for (const auto& countInfo : countInfoSet) { uassert(ErrorCodes::FLEMaxTagLimitExceeded, "Encrypted rewrite tag count overflow", totalTagCount <= std::numeric_limits<uint64_t>::max() - countInfo.count); totalTagCount += countInfo.count; } }
This catches the case where an attacker supplies multiple ESC entries whose counts sum past 2^64 (practically impossible today but defensive).
Acceptance Criteria
- A find command with encryptionInformation whose ESC anchor document encodes cpos = 2^32 returns an FLEMaxTagLimitExceeded error rather than triggering unbounded memory allocation.
- Normal QE equality find operations with legitimate ESC counts are unaffected.
- verifyTagsWillFit receives the true accumulated tag count, not a wrapped value, so the 14 MB default limit is correctly enforced.
- The fix passes ThreadSanitizer and the existing fle_tags unit test suite.
Test Coverage
- Unit test: construct a countInfoSets vector containing one FLEEdgeCountInfo with count = 2^32; call readTags (or the accumulation logic directly) and assert an FLEMaxTagLimitExceeded error is thrown before any tag generation runs.
- Unit test: verify that a count of 2^32 - 1 (just below the 32-bit boundary) also triggers the memory limit check with the correct value.
- Regression test: confirm that the totalTagCount accumulator cannot wrap to a value smaller than any individual countInfo.count.
Worth Fixing Assessment
- Any user with readWrite on a Queryable Encryption-enabled database can crash the entire mongod process with a single find command. This is not a theoretical attack path — SECBUG-1461 includes a working Docker-based PoC that demonstrates unbounded memory growth.
- The damage extends beyond the attacker's own database: the process-level OOM evicts all tenants on the shared mongod, not just the attacker's session.
- The exploit is deterministic and requires no concurrent timing, no admin access, and no special cluster configuration beyond QE being enabled.
- The precondition (PR:L, readWrite access) is normal application-level access. In shared cluster deployments a single low-privilege application credential is sufficient to deny service to all other users.