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

Missing check for message limits, issues with data message counter #54

Closed
Lekensteyn opened this issue Mar 29, 2019 · 2 comments
Closed
Assignees
Labels
bug Something isn't working security review Issues found during Cloudflare internal security review
Milestone

Comments

@Lekensteyn
Copy link

Lekensteyn commented Mar 29, 2019

The protocol defines the following message limits:

  • Rekey-After-Messages 2^64 * 2^16 - 1
  • Reject-After-Messages 2^64 − 2^4 − 1

Although unlikely in practice, the implementation must check that these message limits are not reached and avoid a counter wraparound. The implementation of ReceivingKeyCounterValidator in src/noise/session.rs must be updated to check this.

Right now a malicious implementation could produce the following messages sequence which is accepted by boringtun:

  • counter=0 (sets next to 1 in mark_did_receive)
  • counter=2^64 - 1 (sets next to 0 due to integer overflow)
  • counter=0 (oops! counter reuse - replay accepted!)

Additionally, going from counter 0 to counter 2^64 will also result in a lot of unnecessary executions which facilitates a DoS:

        // Packets where dropped, or maybe reordered, skip them and mark unused
        let mut i = self.next; // 1
        while i < counter { // i = 1 .. 2^64 - 1
            self.clear_bit(i);
            i += 1;
        }

If the gap is too big, perhaps the whole bitmap should be cleared.

FWIW, the WireGuard kernel implementation uses a window of 2048 bits whereas this one uses 1024.

Another related issue is that sending_key_counter and sending_key_counter are an AtomicUsize which may be 32-bit on 32-bit architectures whereas the counter in the protocol is 64-bit.

@Lekensteyn Lekensteyn added bug Something isn't working security review Issues found during Cloudflare internal security review labels Mar 29, 2019
@vkrasnov
Copy link
Contributor

Although unlikely in practice

Impossible in practice.

malicious implementation could produce

But it would only compromise the connection with the malicious implementation itself, not any other connection, I don't really see the problem here.

If the gap is too big, perhaps the whole bitmap should be cleared.

I could have sworn that I implemented that, but apparently I didn't, good catch

@vkrasnov vkrasnov self-assigned this Mar 29, 2019
@vkrasnov vkrasnov added this to the v2.0.1 milestone Mar 29, 2019
@vkrasnov
Copy link
Contributor

vkrasnov commented Apr 1, 2019

I have to merge the PR because it fixes a critical issue, but I will open a new issue that only addresses the limits. Or you are welcome to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security review Issues found during Cloudflare internal security review
Projects
None yet
Development

No branches or pull requests

2 participants