-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/ecdsa: P521 ecdsa.Verify panics with malformed message #60741
Comments
cc @golang/security |
I think I'm generally of the opinion that this is one of the few cases where a panic is reasonable, given that the Verify and VerifyASN1 methods do not have error returns. An incorrect length hash is indicative of something being very wrong, and typically should be something a developer can fix themselves (rather than simply consuming malformed attacker controlled inputs), so panicking and alerting the developer to this, rather than simply silently returning false, feels like the correct approach. At most I think we should maybe document that the hash needs to be the right length? |
@FiloSottile points out that SEC 1, Section 4.1.3 and Section 4.1.4 do specify silent truncation:
This seems like this will just silently cause breakage, but 🤷, the specification is the boss I guess. |
Change https://go.dev/cl/502478 mentions this issue: |
@gopherbot please open a Go 1.20 backport. I think this doesn't have security impact because ECDSA hashes are not attacker-controlled and no one has a 528 hash laying around, but it's a spec deviation leading to a panic, so might as well fix it in Go 1.21 and backport it. |
Backport issue(s) opened: #60744 (for 1.20), #60745 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Here's another one found by OSS-Fuzz where ecdsa.Verify doesn't panic but incorrectly returns false in Go 1.20 and the dev branch, but correctly returns true in 1.19. |
Also fixed by CL 502478 (which is waiting for a Googler +1). |
Change https://go.dev/cl/502915 mentions this issue: |
Before, if a hash was exactly 66 bytes long, we weren't truncating it for use with P-521, because the byte length was not overflowing. However, the bit length could still overflow. Fixes #60744 Updates #60741 Change-Id: I37a0ee210add0eb566e6dc1c141e83e992983eb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/502478 Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]> Reviewed-by: Damien Neil <[email protected]> (cherry picked from commit 886fba5) Reviewed-on: https://go-review.googlesource.com/c/go/+/502915 Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Damien Neil <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, but only the 1.20 branch, not 1.19
What operating system and processor architecture are you using (
go env
)?Linux x64
What did you do?
https://go.dev/play/p/CCW4-OX4nMQ
What did you expect to see?
No panic
What did you see instead?
Found on OSS-Fuzz
The text was updated successfully, but these errors were encountered: