Skip to content

Reject corrupt stream RDB with shared NACK across consumers (CVE-2026-63639) - #4073

Merged
murphyjacob4 merged 1 commit into
valkey-io:unstablefrom
smkher:fix/reject-shared-nack-rdb
Jun 30, 2026
Merged

murphyjacob4 merged 1 commit into
valkey-io:unstablefrom
smkher:fix/reject-shared-nack-rdb

Conversation

@smkher

@smkher smkher commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

When loading a stream consumer group from RDB, the loader assigns each NACK's consumer pointer without checking if it was already set. A corrupt RDB payload can list the same message ID under multiple consumers' PELs, resulting in a shared NACK. This leads to use-after-free when one consumer is deleted while another still references the same NACK.

Add a check that nack->consumer is NULL before assigning. If already set, reject the RDB as corrupt.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 38d48ac9-33ef-4d80-a04b-ce0d41d0d22d

📥 Commits

Reviewing files that changed from the base of the PR and between a9f5b73 and 14371b4.

📒 Files selected for processing (2)
  • src/rdb.c
  • tests/unit/dump.tcl
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/dump.tcl
  • src/rdb.c

📝 Walkthrough

Walkthrough

This change adds a validation during RDB loading of stream consumer-group PEL entries and a regression test that verifies RESTORE rejects a dump corrupted to share one NACK across two consumers.

Changes

RDB Stream NACK Corruption Check

Layer / File(s) Summary
Validate shared NACK assignment in RDB loader
src/rdb.c
Adds a check before assigning a loaded streamNACK to a consumer; if the NACK is already assigned, the loader reports corruption and stops loading.
Restore rejects corrupted shared NACK dump
tests/unit/dump.tcl
Adds a regression test that corrupts a stream dump to create a shared-NACK case across consumers and verifies RESTORE returns a bad data format error.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: rejecting corrupt stream RDB data with shared NACKs across consumers.
Description check ✅ Passed The description accurately explains the RDB loading bug, the corruption case, and the added NULL-check fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/rdb.c (1)

2852-2854: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a brief rationale comment for the new corruption case.

The existing comment above (lines 2849-2851) explains the happy-path assignment but not why a pre-set nack->consumer is rejected (i.e., the use-after-free risk from a message ID shared across multiple consumers' PELs). A short inline note would make this non-obvious safety rationale clear to future readers.

📝 Optional comment addition
+                    /* A NACK must belong to exactly one consumer. If it's already
+                     * assigned, the same message ID appears in multiple consumers'
+                     * PELs, which would cause a dangling reference (use-after-free)
+                     * once one consumer is deleted. Treat this as corruption. */
                     if (nack->consumer) {
                         rdbReportCorruptRDB("NACK already assigned to a consumer, "
                                             "shared NACKs across consumers are not valid");
                         decrRefCount(o);
                         return NULL;
                     }
As per coding guidelines, "Use comments for non-obvious behavior and rationale, not for restating code."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rdb.c` around lines 2852 - 2854, Add a brief inline rationale comment in
the NACK corruption check within the consumer assignment logic around the
nack->consumer guard, explaining that a pre-set consumer is rejected because
sharing a message ID across multiple consumers’ PELs can lead to use-after-free
risk. Keep the note short and tied to the existing corruption branch so future
readers understand why rdbReportCorruptRDB is triggered here.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/rdb.c`:
- Around line 2852-2854: Add a brief inline rationale comment in the NACK
corruption check within the consumer assignment logic around the nack->consumer
guard, explaining that a pre-set consumer is rejected because sharing a message
ID across multiple consumers’ PELs can lead to use-after-free risk. Keep the
note short and tied to the existing corruption branch so future readers
understand why rdbReportCorruptRDB is triggered here.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5627e59d-85c5-4ae2-afb1-88e35f51e4b1

📥 Commits

Reviewing files that changed from the base of the PR and between 5b690ce and f0bdcd1.

📒 Files selected for processing (1)
  • src/rdb.c

@smkher
smkher force-pushed the fix/reject-shared-nack-rdb branch 2 times, most recently from 0e2d4f7 to a9f5b73 Compare June 30, 2026 21:02

@dvkashapov dvkashapov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.78%. Comparing base (01034bf) to head (a9f5b73).
⚠️ Report is 53 commits behind head on unstable.

Files with missing lines Patch % Lines
src/rdb.c 40.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4073      +/-   ##
============================================
+ Coverage     76.61%   76.78%   +0.17%     
============================================
  Files           162      162              
  Lines         80694    81037     +343     
============================================
+ Hits          61823    62224     +401     
+ Misses        18871    18813      -58     
Files with missing lines Coverage Δ
src/rdb.c 77.24% <40.00%> (-0.01%) ⬇️

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

When loading a stream consumer group from RDB, the loader assigns
each NACK's consumer pointer without checking if it was already
claimed by a different consumer. A corrupt RDB payload can list the
same message ID under multiple consumers' PELs, resulting in a
shared NACK. This leads to use-after-free when one consumer is
deleted while another still references the same NACK.

Add a check that rejects the RDB if a NACK is already assigned to a
different consumer. Same-consumer duplicates are still caught by the
existing raxTryInsert check downstream.

Signed-off-by: Saurabh Kher <[email protected]>
@smkher
smkher force-pushed the fix/reject-shared-nack-rdb branch from a9f5b73 to 14371b4 Compare June 30, 2026 21:31
@sarthakaggarwal97 sarthakaggarwal97 moved this to To be backported in Valkey 7.2 Jun 30, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this to To be backported in Valkey 8.0 Jun 30, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this to In Progress / Needs Review in Valkey 8.1 Jun 30, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this from In Progress / Needs Review to To be backported in Valkey 8.1 Jun 30, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this to To be backported in Valkey 9.0 Jun 30, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this to To be backported in Valkey 9.1 Jun 30, 2026

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good!

@murphyjacob4
murphyjacob4 merged commit eefa892 into valkey-io:unstable Jun 30, 2026
60 of 61 checks passed
@z0v3r1n

z0v3r1n commented Jul 1, 2026 •

Copy link
Copy Markdown

Can me and lifip get credited for finding and reporting the vulnerability?

@smkher
smkher deleted the fix/reject-shared-nack-rdb branch July 1, 2026 03:45
valkeyrie-ops Bot pushed a commit that referenced this pull request Jul 1, 2026
When loading a stream consumer group from RDB, the loader assigns each
NACK's consumer pointer without checking if it was already set. A
corrupt RDB payload can list the same message ID under multiple
consumers' PELs, resulting in a shared NACK. This leads to
use-after-free when one consumer is deleted while another still
references the same NACK.

Add a check that nack->consumer is NULL before assigning. If already
set, reject the RDB as corrupt.

Signed-off-by: Saurabh Kher <[email protected]>
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 15, 2026
…key-io#4073)

When loading a stream consumer group from RDB, the loader assigns each
NACK's consumer pointer without checking if it was already set. A
corrupt RDB payload can list the same message ID under multiple
consumers' PELs, resulting in a shared NACK. This leads to
use-after-free when one consumer is deleted while another still
references the same NACK.

Add a check that nack->consumer is NULL before assigning. If already
set, reject the RDB as corrupt.

Signed-off-by: Saurabh Kher <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
@enjoy-binbin enjoy-binbin changed the title fix: Reject corrupt stream RDB with shared NACK across consumers Reject corrupt stream RDB with shared NACK across consumers (CVE-2026-63639) Jul 22, 2026
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 30, 2026
…key-io#4073)

When loading a stream consumer group from RDB, the loader assigns each
NACK's consumer pointer without checking if it was already set. A
corrupt RDB payload can list the same message ID under multiple
consumers' PELs, resulting in a shared NACK. This leads to
use-after-free when one consumer is deleted while another still
references the same NACK.

Add a check that nack->consumer is NULL before assigning. If already
set, reject the RDB as corrupt.

Signed-off-by: Saurabh Kher <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Done
Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants