-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
crypto: panic on invalid aliasing in various APIs #21624
Comments
We assert this property in BoringSSL, I agree that it would be good to do so in Go too. Doing that in C requires undefined behaviour. Is the obvious arithmetic comparison with uintptrs guaranteed to work in Go? (Or, at least, is it guaranteed not to false positive? It's possible that I shied away from doing this initially because of worries like “what if a GC happens between these two lines and moves the buffer?”) |
By my reading of https://golang.org/pkg/unsafe/#Pointer simply using Implementing it in assembly would definitely work. I guess the generic code could be left to a no-op not to require implementations for all platforms right away. But yeah, no inlining. |
Writing it in Go is fine. Just put me on the review list. It's the standard library - we can assume things not guaranteed by the spec, and it's on us to keep them working. Go is much better than assembly times N architectures. |
Change https://golang.org/cl/63915 mentions this issue: |
I've now debugged multiple mysterious "inability to communicate" bugs that manifest as a silent unexplained authentication failure but are really crypto.AEAD.Open being invoked with badly aligned buffers. In #21624 I suggested using a panic as the consequence of bad alignment, so that this kind of failure is loud and clearly different from, say, a corrupted or invalid message signature. Adding the panic here made my failure very easy to track down, once I realized that was the problem. I don't want to debug another one of these. Also using this CL as an experiment to get data about the impact of maybe applying this change more broadly in the master branch. Change-Id: Id2e2d8e980439f8acacac985fc2674f7c96c5032 Reviewed-on: https://go-review.googlesource.com/63915 Reviewed-by: Adam Langley <agl@golang.org>
Change https://golang.org/cl/65486 mentions this issue: |
I've now debugged multiple mysterious "inability to communicate" bugs that manifest as a silent unexplained authentication failure but are really crypto.AEAD.Open being invoked with badly aligned buffers. In #21624 I suggested using a panic as the consequence of bad alignment, so that this kind of failure is loud and clearly different from, say, a corrupted or invalid message signature. Adding the panic here made my failure very easy to track down, once I realized that was the problem. I don't want to debug another one of these. Also using this CL as an experiment to get data about the impact of maybe applying this change more broadly in the master branch. Change-Id: Id2e2d8e980439f8acacac985fc2674f7c96c5032 Reviewed-on: https://go-review.googlesource.com/63915 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-on: https://go-review.googlesource.com/65486 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
I have pending CLs for this but they did not go out in time. Next cycle. |
Change https://golang.org/cl/109697 mentions this issue: |
Here's my proposal for
Making it return a bool instead of panic'ing helps with inlining and lets us write better panic messages. |
Based on discussion with @agl, @bradfitz and @ianlancetaylor:
|
Change https://golang.org/cl/112236 mentions this issue: |
…across packages AnyOverlap and InexactOverlap implement checks for the aliasing requirements defined by the crypto/cipher interfaces. Apply them to all implementations as the actual requirement could be architecture-dependent and user code should not rely on undefined behavior. Updates golang/go#21624 Change-Id: I465de02fb3fec4e0c6f1fdee1ef6ae7ed5abff10 Reviewed-on: https://go-review.googlesource.com/112236 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The cipher.AEAD docs say for Open:
I just spent a few hours debugging a problem that ended up being a call to cipher.AEAD.Open
with inexact aliasing that was accepted and implemented "correctly" by one implementation
of cipher.AEAD (the crypto/aes GCM one) but rejected (as permitted) by a different implementation.
The docs above give a constraint on the nonce size and on the aliasing.
The AES-GCM implementation panics if the nonce size is incorrect but
does nothing if the aliasing is incorrect. I suggest it panic too.
More generally, I suggest that everywhere we document a restriction
about the aliasing of input and output buffers we enforce that restriction
with a check and panic.
We can add to crypto/subtle
and implement these in a way that inlines.
/cc @agl
The text was updated successfully, but these errors were encountered: