Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up the receive window check #49

Merged
merged 3 commits into from
Feb 18, 2021
Merged

Conversation

marten-seemann
Copy link
Contributor

The receive window was performed in TryReserve:

go-yamux/util.go

Lines 125 to 133 in fad228e

func (s *segmentedBuffer) TryReserve(space uint32) bool {
s.bm.Lock()
defer s.bm.Unlock()
if s.cap < s.pending+space {
return false
}
s.pending += space
return true
}

Note the uint32 overflow.

The only reason this overflow can't be exploited is that it's not possible that pending is unequal 0 after calling Append (unless Append errors, in which case we close the connection anyway). This is the only way we use those two functions:

go-yamux/stream.go

Lines 425 to 435 in fad228e

// Validate it's okay to copy
if !s.recvBuf.TryReserve(length) {
s.session.logger.Printf("[ERR] yamux: receive window exceeded (stream: %d, remain: %d, recv: %d)", s.id, s.recvBuf.Cap(), length)
return ErrRecvWindowExceeded
}
// Copy into buffer
if err := s.recvBuf.Append(conn, int(length)); err != nil {
s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err)
return err
}

That means that the pending member variable is not actually used for anything useful, and can be removed by merging TryReserve and Append. This is what this PR does.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

👍

@marten-seemann marten-seemann merged commit 35dde00 into master Feb 18, 2021
@marten-seemann marten-seemann deleted the cleanup-window-check branch February 18, 2021 01:54
@Stebalien Stebalien mentioned this pull request May 11, 2021
27 tasks
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants