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
forbid key discarding before receiving a packet protected with new keys #4079
Merged
martinthomson
merged 3 commits into
quicwg:master
from
marten-seemann:fix-key-update-deadlock
Sep 10, 2020
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the first sentence, I think SHOULD works too, but I agree that MUST is better here.
I do not think we need the second sentence, as we state that an endpoint "SHOULD retain no more than 3 PTO" down below.
I think the crux of the problem is the last two sentences that are left unmodified. As correctly pointing out by the issue, the outcome of discarding the keys too early is more than just a performance degradation. Doing so might kill the connection. We should state that clearly, and then the choice of the keyword in the first sentence becomes more of an editorial preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just a performance issue provided the initiator keeps sending. You lose some reordered packets and have spurious detection of some extra packet loss. Where the connection hard-fails is when the peer never updates / learns about the update because the initiator stops sending after the key update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I agree. The point is that the initiator is not required to keep sending.
As @marten-seemann points out, an endpoint that only receives data (but does not send any) might decide to do a key update. If that endpoint drops the old receive key before any of the packets it sent reaches the peer, the connection will be stuck.
That is because all the ack-eliciting packets involved will be the ones that are sent by the peer using the old key, which the endpoint has dropped that key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here's what happens when you initiate a key update from key phase N to N+1: You start using N+1 for encrypting packets. As it's not guaranteed that those packets are received by the peer, it's not safe to drop keys for key phase N yet. You only know that the peer received a packet protected with N+1 keys once you successfully unprotect a packet encrypted with N+1 keys (as the peer is required to update its keys immediately once it receives your N+1 packet).
From this point on, it is safe to drop key N. However, it's not recommended, as there might be reordering, so keeping the key for a bit longer allows you to process delayed packets. At this point, this is just a performance optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's safe to drop key N when you receive packets protected with key N+1. And it's true that keeping keys for a short while helps avoid dropping reordered packets.
However, it it generally safer to only drop key N when you receive an acknowledgment for a packet sent with N+1 keys. Because the other side might have updated on its own. That means that the N+1 packet you received isn't any indication that they received your key update. This distinction doesn't matter for dropping keys, but it does matter for determining whether you can initiate an update to N+2 keys later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. In my mental model (and in my implementation), these are two separate conditions though. I can start the timer to drop the keys before I'm allowed to update to N+2.
Do you think we need to make any changes to this text here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it's OK to have two events, and technically the drop events are bound to use of keys. In that regard, I'm comfortable with the text you have. I don't think we need to rely exclusively on acknowledgments for driving this.