Skip to content

tenantcapabilitieswatcher: fix nil deref removing placeholder entry#168391

Merged
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
stevendanna:fix-tenant-capabilities-nil-deref
Apr 30, 2026
Merged

tenantcapabilitieswatcher: fix nil deref removing placeholder entry#168391
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
stevendanna:fix-tenant-capabilities-nil-deref

Conversation

@stevendanna
Copy link
Copy Markdown
Collaborator

@stevendanna stevendanna commented Apr 15, 2026

The Watcher's getInternal method inserts a placeholder watcherEntry
with a nil embedded *Entry pointer when a reader queries capabilities
for a tenant not yet seen by the rangefeed. If removeEntryForTenantIDLocked
was later called for that tenant, it accessed entry.Name through the nil
embedded pointer, causing a panic.

This can occur when a rangefeed restart re-delivers a delete event for
a tenant whose entry was already removed during a previous rangefeed
lifetime. If a reader called GetInfo for that tenant in the interim,
the store contains only the nil-Entry placeholder, and the re-delivered
delete dereferences it.

Epic: none

The Watcher's getInternal method inserts a placeholder watcherEntry
with a nil embedded *Entry pointer when a reader queries capabilities
for a tenant not yet seen by the rangefeed. If removeEntryForTenantIDLocked
was later called for that tenant, it accessed entry.Name through the nil
embedded pointer, causing a panic.

This can occur when a rangefeed restart re-delivers a delete event for
a tenant whose entry was already removed during a previous rangefeed
lifetime. If a reader called GetInfo for that tenant in the interim,
the store contains only the nil-Entry placeholder, and the re-delivered
delete dereferences it.

Epic: none
Release note (bug fix): Fixed a rare nil pointer dereference panic in
the tenant capabilities watcher that could occur when a tenant entry
was removed before it was fully populated by the rangefeed.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@stevendanna stevendanna requested a review from a team as a code owner April 15, 2026 12:37
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Apr 15, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@stevendanna stevendanna added the backport-all Flags PRs that need to be backported to all supported release branches label Apr 15, 2026
// duplicate delete. A duplicate delete interleaved with a
// getInternal call can also result is us finding an entry
// with a nil value for the embedded Entry struct.
if entry, ok := w.mu.store[tid]; ok && entry.Entry != nil {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There is another question about the downstream affects of notifying a change of a tenant (from a previous GetInfo call) that no longer exists. But, we still shouldn't panic here in that case.

@stevendanna stevendanna requested review from cthumuluru-crdb and shubhamdhama and removed request for cthumuluru-crdb April 17, 2026 17:16
Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

:lgtm:

@arulajmani reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on shubhamdhama).

@stevendanna
Copy link
Copy Markdown
Collaborator Author

/trunk merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-all Flags PRs that need to be backported to all supported release branches target-release-26.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants