[BUG] harden single-node deployment against memory-safety and DoS attacks#7098
Open
rescrv wants to merge 3 commits into
Open
[BUG] harden single-node deployment against memory-safety and DoS attacks#7098rescrv wants to merge 3 commits into
rescrv wants to merge 3 commits into
Conversation
…acks Address five chained vulnerabilities in the single-node (sqlite + local HNSW) deployment that together enable unauthenticated heap corruption with a credible path to remote code execution. Dimension TOCTOU (CWE-367 → CWE-787/CWE-125): - Add a per-collection mutex around dimension initialization in validate_embedding so concurrent /add requests cannot race to set conflicting dimensions. - Validate persisted HNSW header dimensionality on cold-load against the sysdb dimension; reject mismatches before constructing the index. - Stage id_map mutations in a pending copy during apply_log_chunk and commit only on success, preventing partial state on error. - Validate embedding dimensionality per-record in the HNSW writer. Unbounded HNSW configuration (CWE-20/CWE-1284 → CWE-770): - Add upper bounds to all HNSW tunables: max_neighbors ≤ 128, ef_construction ≤ 4096, ef_search ≤ 4096, resize_factor ≤ 10.0, sync_threshold ≤ 4096. - Enforce bounds at every ingestion point: schema validation, InternalCollectionConfiguration, UpdateCollectionConfiguration, and the compaction pipeline. - Skip HNSW backfill for collections with invalid persisted config but still advance the metadata watermark so log purging proceeds. Concurrent cache-miss race (CWE-362 → CWE-664): - Introduce a partitioned async mutex (AysncPartitionedMutex) in LocalSegmentManager keyed on IndexUuid. Double-check the cache after acquiring the lock to prevent two HnswIndex instances from sharing the same on-disk segment directory. delete_collection resource leak (CWE-401/CWE-772 → CWE-400): - Actively evict and close HNSW indexes on collection deletion. - Delete on-disk segment directories via tombstone-rename + periodic background cleanup of orphaned HNSW index dirs (6-hour age gate). - Purge sqlite log rows for deleted collections. - Propagate segment deletion through delete_database as well. - Serialize database-level create/delete behind a per-database lock. Log purge skipped on backfill error (CWE-754 → CWE-400): - Always dispatch PurgeLogsMessage after BackfillMessage regardless of backfill outcome; the purge handler independently computes watermarks from persisted segment state. - For collections with invalid HNSW config, fall back to the metadata-segment watermark so logs do not accumulate unboundedly. Where-clause stack overflow: - Cap $or/$and recursion depth at 64 in both parse_where and parse_where_document to prevent attacker-triggered stack overflow that could crash the tokio runtime. Co-authored-by: AI
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
This comment has been minimized.
This comment has been minimized.
This was referenced May 20, 2026
This comment has been minimized.
This comment has been minimized.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
Address five chained vulnerabilities in the single-node (sqlite + local HNSW)
deployment that together enable unauthenticated heap corruption with a
credible path to remote code execution.
Dimension TOCTOU (CWE-367 → CWE-787/CWE-125):
validate_embedding so concurrent /add requests cannot race to set
conflicting dimensions.
sysdb dimension; reject mismatches before constructing the index.
commit only on success, preventing partial state on error.
Unbounded HNSW configuration (CWE-20/CWE-1284 → CWE-770):
ef_construction ≤ 4096, ef_search ≤ 4096, resize_factor ≤ 10.0,
sync_threshold ≤ 4096.
InternalCollectionConfiguration, UpdateCollectionConfiguration,
and the compaction pipeline.
but still advance the metadata watermark so log purging proceeds.
Concurrent cache-miss race (CWE-362 → CWE-664):
LocalSegmentManager keyed on IndexUuid. Double-check the cache
after acquiring the lock to prevent two HnswIndex instances from
sharing the same on-disk segment directory.
delete_collection resource leak (CWE-401/CWE-772 → CWE-400):
background cleanup of orphaned HNSW index dirs (6-hour age gate).
Log purge skipped on backfill error (CWE-754 → CWE-400):
of backfill outcome; the purge handler independently computes
watermarks from persisted segment state.
metadata-segment watermark so logs do not accumulate unboundedly.
Where-clause stack overflow:
parse_where_document to prevent attacker-triggered stack overflow
that could crash the tokio runtime.
Test plan
Local testing of new tests + CI for our full suite.
Migration plan
This code migrates itself.
Observability plan
N/A
Documentation Changes
Will need to update docs to document limitations and recovery for corrupted hnsw segments.
Co-authored-by: AI