Fix TOCTOU race in gossip discovery handleAliveMessage#5397
Open
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Open
Fix TOCTOU race in gossip discovery handleAliveMessage#5397Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Conversation
Consolidate three separate RLock/RUnlock pairs into a single atomic
read to prevent concurrent purge() from removing a member between
checks, which caused a panic ("not found in alive nor dead") or nil
pointer dereference in learnExistingMembers.
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Contributor
Author
|
Hi @yacovm, when you get a chance, could you please review this PR? |
Contributor
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.
Type of change
Description
This PR fixes a TOCTOU race in gossip discovery that could crash a peer during normal operation.
handleAliveMessage()previously read membership state using multiple separateRLock/RUnlocksections and then treated the combined result as consistent. If a concurrentpurge()ran between these lock gaps (for example during identity changes or message expiration), a member could appear as “known” but neither alive nor dead, triggering aPanicf. In another path, the same race could lead to a nil pointer dereference inlearnExistingMembers().The fix consolidates all membership state reads into a single atomic
RLocksection and adds a defensive nil guard when updating existing members. This ensures inconsistent intermediate states are never observable and avoids crashing the peer.Additional details
The change is localized to gossip discovery logic and does not affect normal behavior.
Tested locally with
go test ./gossip/....Release Note
Fixes a gossip discovery race where concurrent member purging could cause
a peer panic during normal operation.