Repository navigation
Conversation
keepAliveTimer is assigned only inside the non-zero hold time check in openSent, and the fsm constructor does not initialise it, so a negotiated hold time of zero leaves it nil. openConfirm and established then read from it unconditionally and both cleanup paths call Stop on it, which panics. There is no recover in fsm.run, so this takes down the process rather than the peer. Hold Time 0 is legal: RFC 4271 section 4.2 gives it the meaning that the hold timer is never started. Negotiation takes the lower of the two speakers' values, so a remote peer produces it regardless of the local configuration, and a Plugin cannot refuse it because OnOpenMessage is not given the hold time. Every use now goes through nil-safe helpers, so a nil timer means no keepalives and no expiry, which is what a zero hold time specifies. Receiving from a nil channel blocks forever, which gives that behaviour in a select without a special case at each site. The keepalive manager's existing "if f.holdTime != 0" guard is subsumed by resetKeepAliveTimer.
Contributor
|
@jwhited I need this as well if you have time to review. Thanks! |
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.
A peer advertising Hold Time 0 panics the FSM
What happens
fsm.keepAliveTimeris only ever assigned inside a non-zero hold time check inopenSent:The struct field is never initialised elsewhere - the constructor sets
idleHoldTimerbut not this one - so a negotiated hold time of zero leaves it nil.openConfirmthen reads from it unconditionally:which is a nil pointer dereference.
establisheddoes the same, and both states' cleanup paths callf.keepAliveTimer.Stop().There is no
recoverinfsm.run, so this takes down the whole process, not just the peer.Why it is reachable
Hold Time 0 is legal. RFC 4271 section 4.2:
The negotiation takes the minimum of the two speakers' values, so a remote peer sending 0 produces 0 regardless of what the local side configured. A local
WithHoldTime(0)does the same.That makes it reachable from the other end of the connection: a speaker which accepts inbound sessions can be crashed by a peer that offers Hold Time 0, whether by misconfiguration or deliberately. A
Plugincannot defend againstit either, since
OnOpenMessageis not given the hold time.The invariant is already understood in one place - the keepalive manager goroutine guards its reset with
if f.holdTime != 0- so this looks like the same check missing from the other five uses rather than a design intent.Fix
The attached patch routes every use through three small helpers, so a nil timer means "no keepalives, never expires", which is what a zero hold time is specified to mean. A nil channel in a
selectblocks forever, which gives that behaviour without a special case at each site.Applies to v0.8.5. Verified: builds,
go vetclean, and the existing test suite passes.A regression test
Not included, because reproducing it needs an OPEN exchange and
TestServercurrently covers peer bookkeeping rather than session establishment. Happy to add one against whatever harness you would prefer - two servers peering over loopback withWithHoldTime(0)on one side reproduces it.Note on a related semantic
With the panic fixed, a zero hold time still leaves
holdTimerrunning at thelongHoldTimeit was given before negotiation, becausedrainAndResetHoldTimeris only called on the non-zero path. So the session would be torn down when that expires, where RFC 4271 says the timer should never start. That is a separate change and not in this patch.