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

Fix handling of retransmitted cookie-echo #130

Merged
merged 5 commits into from
Jul 15, 2020
Merged

Conversation

enobufs
Copy link
Member

@enobufs enobufs commented Jul 6, 2020

Relates to pion/webrtc#1270

Description

Please see this comment(pion/webrtc#1270 (comment)) for details.

What's in this PR

  • Fixed the issue by sending COOKIE-ACK on the receipt of COOKIE-ECHO even in the Established state.
  • Added a reproducible test using vnet, successfully confirmed the problem, and the fix.

@codecov
Copy link

codecov bot commented Jul 6, 2020

Codecov Report

Merging #130 into master will increase coverage by 0.10%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #130      +/-   ##
==========================================
+ Coverage   78.71%   78.82%   +0.10%     
==========================================
  Files          43       43              
  Lines        2795     2800       +5     
==========================================
+ Hits         2200     2207       +7     
+ Misses        457      455       -2     
  Partials      138      138              
Flag Coverage Δ
#go 78.82% <64.28%> (+0.10%) ⬆️
#wasm 69.96% <64.28%> (+0.23%) ⬆️
Impacted Files Coverage Δ
association.go 82.63% <64.28%> (-0.11%) ⬇️
chunkheader.go 82.14% <0.00%> (+7.14%) ⬆️
chunk_cookie_ack.go 69.23% <0.00%> (+15.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd77f5a...ee0cd3c. Read the comment docs.

@enobufs enobufs self-assigned this Jul 6, 2020
@enobufs enobufs requested a review from Sean-Der July 6, 2020 07:32
@enobufs enobufs force-pushed the fix-cookie-echo-handling branch from 0357fc7 to 892b525 Compare July 6, 2020 09:38
@enobufs enobufs force-pushed the fix-cookie-echo-handling branch from 892b525 to 9119023 Compare July 13, 2020 17:08
@enobufs
Copy link
Member Author

enobufs commented Jul 14, 2020

@Sean-Der This is a fix for a fundamental error in handling delayed cookie-echo received in the "established" state (which would happen over lossy connection). If you could review this at your earliest convenience, that would really be appreciated.

association.go Outdated Show resolved Hide resolved
enobufs added 3 commits July 14, 2020 22:35
This is related to #62 in which we removed the use of immediate ack (I)
bit. This test became unstable as we no longer use immediate ack.
Relates to pion/webrtc#1270
@enobufs enobufs force-pushed the fix-cookie-echo-handling branch from ae7ec58 to ae15c0e Compare July 15, 2020 05:36
@at-wat
Copy link
Member

at-wat commented Jul 15, 2020

$ bash .github/lint-commit-message.sh
Update association.go

Accepted the change.

Co-authored-by: Atsushi Watanabe <atsushi.w@ieee.org>

-------------------------------------------------
The preceding commit message is invalid
it failed 'Separate subject from body with a blank line' of the following checks

* Separate subject from body with a blank line
* Limit the subject line to 50 characters
* Capitalize the subject line
* Do not end the subject line with a period
* Wrap the body at 72 characters

Commit message from GitHub web UI uses CR+LF which is currently not supported by our commit message lint script. pion/.goassets#6

git commit --amend and remove CR will fix the error.

@enobufs enobufs force-pushed the fix-cookie-echo-handling branch from ae15c0e to e9599dc Compare July 15, 2020 06:46
return nil
}
case established:
Copy link
Member

Choose a reason for hiding this comment

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

Current implementation seems returning cookie-ack whenever cookie-echo is received after established.
https://tools.ietf.org/html/rfc4960#section-5.2.4 seems to specify several conditions/actions and cookie-echo should be silently discarded in some case.

Copy link
Member Author

@enobufs enobufs Jul 15, 2020

Choose a reason for hiding this comment

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

@at-wat Yes, good finding. The current implementation does not follow the RFC for building a cookie. It is currently a random value that prevents us from validating the echoed cookie as specified in the RFC.

I am hoping to address this issue in #74 sometime soon, encoding TCB information into the cookie, then validate as the spec says. (no effect in WebRTC usage however, if we provide Listen/Dial semantics, yes it is desired.)

This pull-request tries to address missing state transitions from COOKIE-ECHOED to ESTABLISHED because the peer in the ESTABLISHED state does not send COOKIE-ACK, a different issue. We are seeing the connection stalled in the real world because of this.

Copy link
Member

Choose a reason for hiding this comment

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

I am hoping to address this issue in #74 sometime soon, encoding TCB information into the cookie, then validate as the spec says.

Great!
Maybe it's better to notify the current status of the implementation in README. If users try to use the library as a full sctp implementation, simplified implementation may cause some security problems. (as it's over DTLS in WebRTC, we don't have to care.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @at-wat You just made me realize we at least needed to check if the echoed cookie was identical to the original one. Thanks!

Let me add these lines in the "established" case.

		if !bytes.Equal(a.myCookie.cookie, c.cookie) {
			return nil
		}

When the cookie does not match, it will silently be discarded.

Copy link
Member Author

Choose a reason for hiding this comment

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

@at-wat a quick question. Use used 'break' inside the switch statement. Golang does not require break but is that something you'd recommend for readability or any other reasons? (just out of my curiosity...)

Copy link
Member

Choose a reason for hiding this comment

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

I don't have strong reason, but I just feel it's more clear to tell that it's not fallthrough. (I mainly used C/C++ before starting Go)

Copy link
Member Author

Choose a reason for hiding this comment

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

@at-wat I have just added the cookie comparison to the established case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hear you. I write C/C++ too. ;) but I am trying to think in Go. I removed it in the last commit, hope you wouldn't mind...

Copy link
Member

Choose a reason for hiding this comment

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

It's 100% fine to me!

Copy link
Member

@at-wat at-wat left a comment

Choose a reason for hiding this comment

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

LGTM!

@enobufs enobufs merged commit 248c545 into master Jul 15, 2020
@enobufs enobufs deleted the fix-cookie-echo-handling branch July 15, 2020 08:44
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.

2 participants