Repository navigation
MOD-13409 Harden RDB loading (backport to 8.4) - #1039
Conversation
* MOD-13409 Validate Bloom RDB bitset size on load (#126) * MOD-13409 Validate Bloom RDB bitset size on load Reject crafted module payloads where the loaded bloom bitset buffer length does not match the declared bits/n2, and add a flow regression test covering RESTORE with a corrupted DUMP payload. * MOD-13409 clang-format rebloom.c Run clang-format on rebloom.c to satisfy make lint formatting checks. * MOD-13409 Validate Bloom RDB bitset length on load Reject crafted module payloads where persisted bits do not match the loaded bitset buffer length, preventing OOB access after RESTORE. (cherry picked from commit ecbdc81) * Mod 13409 rdb hardening (#127) * MOD-13409 clang-format rebloom.c Run clang-format on rebloom.c to satisfy make lint formatting checks. * MOD-13409 Harden CF RDB load buffer validation Replace assert-only checks in CFRdbLoad with explicit validation of loaded sizes and ranges, and add a flow test that corrupts a CF DUMP payload to ensure RESTORE is rejected. * MOD-13409 Harden remaining RDB loaders (TDigest) TDigest RDB loading trusted attacker-controlled cap, which could desync the allocated centroid arrays from the loaded metadata and enable OOB access after RESTORE. Reject payloads where loaded cap differs from the allocated cap derived from compression, validate node counters, and add a flow regression that corrupts a TDigest DUMP payload and asserts RESTORE is rejected. With the earlier BF/CF fixes, this covers all remaining module data structures that load raw buffers from RDB/RESTORE (CMS/TopK already validate buffer sizes). * Revert "MOD-13409 clang-format rebloom.c" This reverts commit 456e53503f51b68c4d7a9df988e50a36adf2e61a. (cherry picked from commit a4b4f80)
| raise RuntimeError(f"Unknown module opcode {opcode} at pos={pos}") | ||
|
|
||
| if not patched: | ||
| raise RuntimeError("Did not find target SINT to patch") |
There was a problem hiding this comment.
Test helper missing SINT opcode breaks TDigest test
High Severity
_corrupt_dump_set_first_uint_after_3_doubles only handles RDB_MODULE_OPCODE_UINT (2), RDB_MODULE_OPCODE_DOUBLE (4), RDB_MODULE_OPCODE_STRING (5), and RDB_MODULE_OPCODE_EOF (0). TDigest saves cap via RedisModule_SaveSigned, which emits a SINT opcode (value 1). After parsing the 3 doubles (compression, min, max), the parser encounters opcode 1, matches none of the handled cases, and raises RuntimeError("Unknown module opcode 1"). This prevents the TDigest corruption test from functioning. Additionally, the function applies _zigzag_encode to the replacement value, but RedisModule_SaveSigned uses a raw reinterpret cast, not zigzag encoding, so the patched value would be wrong even if parsing succeeded.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9d572c2. Configure here.
Avoid signed overflow when validating merged and unmerged node counts by widening the addition.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b2943e9. Configure here.
| raise RuntimeError(f"Unknown module opcode {opcode} at pos={pos}") | ||
|
|
||
| if not patched: | ||
| raise RuntimeError("Did not find target SINT to patch") |
There was a problem hiding this comment.
Test helper misses SINT opcode, TDigest corruption test fails
High Severity
_corrupt_dump_set_first_uint_after_3_doubles only handles module opcodes EOF (0), UINT (2), DOUBLE (4), and STRING (5), but not SINT (1). The TDigest save function uses RedisModule_SaveSigned for cap (producing SINT opcode 1) immediately after the three doubles. When parsing a TDigest dump, the function encounters opcode 1 and falls through to raise RuntimeError("Unknown module opcode 1"). The error message at line 171 ("Did not find target SINT to patch") confirms the intent was to patch a SINT field, but the parser never handles that opcode. The test_restore_rejects_corrupted_tdigest_cap test will always fail with an unhandled RuntimeError before reaching the RESTORE command.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit b2943e9. Configure here.
## Summary Bumps the RedisBloom pin on `8.4` from `v8.4.5` to `v8.4.8`. | Module | From | To | |---|---|---| | RedisBloom | `v8.4.5` | `v8.4.8` | ## RedisBloom changes ([v8.4.5...v8.4.8](RedisBloom/RedisBloom@v8.4.5...v8.4.8)) - MOD-16050 — Replicate `CF.LOADCHUNK` data chunks to prevent silent Cuckoo Filter data loss on failover ([#1020](RedisBloom/RedisBloom#1020)) - MOD-13409 — Harden RDB loading, including validation of crafted module payloads ([#1039](RedisBloom/RedisBloom#1039)) ## Test plan - [x] Confirmed `v8.4.8` exists in RedisBloom - [x] Validated `modules/redisbloom/Makefile` pins `MODULE_VERSION` to `v8.4.8` - [ ] Redis core CI passes with the updated module pin <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Module upgrade touches replication and persistence parsing; failures could affect Bloom/Cuckoo data durability or availability on load, though scope is limited to the RedisBloom pin. > > **Overview** > Bumps the RedisBloom build pin from **v8.4.5** to **v8.4.8** by updating `MODULE_VERSION` in `modules/redisbloom/Makefile`, so `get_source` clones and builds the newer upstream tag. > > That range pulls in upstream fixes for **Cuckoo Filter replication** (`CF.LOADCHUNK` chunks replicated to avoid data loss on failover) and **stricter RDB load validation** for crafted module payloads. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1f168a9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->





Summary
Backport of #1038 to 8.4.
Testing
Note
High Risk
Changes deserialization of persisted module data—a security-sensitive path where bad input could cause OOM, buffer over-reads, or memory corruption; mitigated by explicit bounds checks and new regression tests.
Overview
Backports RDB load hardening for RedisBloom on the 8.4 line (patch 8.4.5 → 8.4.8), so crafted DUMP/RESTORE payloads are rejected instead of trusting serialized metadata.
Bloom (
BFRdbLoad): validates the bitset buffer (non-null, sane size), ties bits to buffer length for newer encodings, and checksn2/ modulus consistency beforebloom_validate_integrity.Cuckoo (
CFRdbLoad): bounds numFilters, numBuckets, and tuning fields; runsCuckooFilter_ValidateIntegritybefore loading sub-filter blobs; requires power-of-two bucket counts and exact expected buffer sizes (replacingassert-only checks).TDigest (
TDigestRdbLoad): ensurescapmatches whattd_newallocated and that merged/unmerged node counts stay within that capacity before reading node arrays.Adds flow tests that shrink module string blobs or inflate TDigest
capin DUMP payloads and assert RESTORE fails while the server stays healthy.Reviewed by Cursor Bugbot for commit b2943e9. Bugbot is set up for automated code reviews on this repo. Configure here.