-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/x509: Certificate.Verify crash on macOS with Go 1.18 #51759
Comments
Minimal repro: package main
import (
"log"
"net/http"
"os"
)
func main() {
res, err := http.Get("https://derp10.tailscale.com")
if err != nil {
log.Fatal(err)
}
res.Write(os.Stdout)
} |
Interestingly, |
I see that |
@AGWA, ah, right! We send that along to clients to save an RTT. |
Same here
|
Brad and I have a diagnosis, working on a fix and test. They'll be ready soon. |
Change https://go.dev/cl/393655 mentions this issue: |
diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
index 1ef9c0f71e..ad365f577e 100644
--- a/src/crypto/x509/root_darwin.go
+++ b/src/crypto/x509/root_darwin.go
@@ -13,6 +13,9 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
certs := macOS.CFArrayCreateMutable()
defer macOS.ReleaseCFArray(certs)
leaf := macOS.SecCertificateCreateWithData(c.Raw)
+ if leaf == 0 {
+ return nil, errors.New("invalid leaf certificate")
+ }
macOS.CFArrayAppendValue(certs, leaf)
if opts.Intermediates != nil {
for _, lc := range opts.Intermediates.lazyCerts {
@@ -21,7 +24,9 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
return nil, err
}
sc := macOS.SecCertificateCreateWithData(c.Raw)
- macOS.CFArrayAppendValue(certs, sc)
+ if sc != 0 {
+ macOS.CFArrayAppendValue(certs, sc)
+ }
}
}
diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go
index f4ea08bbf5..100a8ff0f9 100644
--- a/src/crypto/x509/verify_test.go
+++ b/src/crypto/x509/verify_test.go
@@ -1876,3 +1876,37 @@ func TestSystemRootsErrorUnwrap(t *testing.T) {
t.Error("errors.Is failed, wanted success")
}
}
+
+func TestIssue51759(t *testing.T) {
+ // badCertData contains a cert that we parse as valid
+ // but that macOS SecCertificateCreateWithData rejects.
+ const badCertData = "0\x82\x01U0\x82\x01\a\xa0\x03\x02\x01\x02\x02\x01\x020\x05\x06\x03+ep0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260\x1e\x17\r220112235755Z\x17\r220313235755Z0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260*0\x05\x06\x03+ep\x03!\x00bA\xd8e\xadW\xcb\xefZ\x89\xb5\"\x1eR\x9d\xba\x0e:\x1042Q@\u007f\xbd\xfb{ks\x04\xd1£\x020\x000\x05\x06\x03+ep\x03A\x00[\xa7\x06y\x86(\x94\x97\x9eLwA\x00\x01x\xaa\xbc\xbd Ê]\n(΅!ف0\xf5\x9a%I\x19<\xffo\xf1\xeaaf@\xb1\xa7\xaf\xfd\xe9R\xc7\x0f\x8d&\xd5\xfc\x0f;Ϙ\x82\x84a\xbc\r"
+ badCert, err := ParseCertificate([]byte(badCertData))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ t.Run("leaf", func(t *testing.T) {
+ opts := VerifyOptions{}
+ _, err = badCert.Verify(opts)
+ if err == nil {
+ t.Fatal("expected error")
+ }
+ })
+
+ goodCert, err := certificateFromPEM(googleLeaf)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ t.Run("intermediate", func(t *testing.T) {
+ opts := VerifyOptions{
+ Intermediates: NewCertPool(),
+ }
+ opts.Intermediates.AddCert(badCert)
+ _, err = goodCert.Verify(opts)
+ if err == nil {
+ t.Fatal("expected error")
+ }
+ })
+} |
Upstream at https://go-review.googlesource.com/c/go/+/393655 Fixes golang#51759 Co-authored-by: Josh Bleecher Snyder <josharian@gmail.com> Change-Id: I0a6f2623b57750abd13d5e194b5c6ffa3be6bf72 (cherry picked from commit 480b3dc018636ffb8c14236b3db25d2d5a926249)
Due to golang/go#51759 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Due to golang/go#51759 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@gopherbot please consider this for backport to 1.18, it's a regression |
Backport issue(s) opened: #51763 (for 1.18). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Note for posterity: |
See golang/go#51759 (comment) Once we deploy this, tailscaled should work again for macOS users with Go 1.18. Updates golang/go#51759 Change-Id: I869b6ddc556a2de885e96ccf9f335dfc8f6f6a7e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
See golang/go#51759 (comment) Once we deploy this, tailscaled should work again for macOS users with Go 1.18. Updates golang/go#51759 Change-Id: I869b6ddc556a2de885e96ccf9f335dfc8f6f6a7e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
See golang/go#51759 (comment) Once we deploy this, tailscaled should work again for macOS users with Go 1.18. Updates golang/go#51759 Change-Id: I869b6ddc556a2de885e96ccf9f335dfc8f6f6a7e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
See golang/go#51759 (comment) Once we deploy this, tailscaled should work again for macOS users with Go 1.18. Updates golang/go#51759 Change-Id: I869b6ddc556a2de885e96ccf9f335dfc8f6f6a7e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change https://go.dev/cl/394655 mentions this issue: |
Change https://go.dev/cl/394674 mentions this issue: |
Like we did in ead16b2 for tailscaled. Updates #4258 Due to golang/go#51759 Change-Id: I6effcea7c5f2ec264b9711f4c316f8fca09490f1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Like we did in ead16b2 for tailscaled. Updates #4258 Due to golang/go#51759 Change-Id: I6effcea7c5f2ec264b9711f4c316f8fca09490f1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Updates #51759 Change-Id: Ib73fa5ec62d90c7e595150217b048158789f1afd Reviewed-on: https://go-review.googlesource.com/c/go/+/394674 Run-TryBot: Filippo Valsorda <filippo@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
(Primarily from Josh) Updates #51759 Fixes #51763 Fixes CVE-2022-27536 Co-authored-by: Josh Bleecher Snyder <josharian@gmail.com> Change-Id: I0a6f2623b57750abd13d5e194b5c6ffa3be6bf72 Reviewed-on: https://go-review.googlesource.com/c/go/+/393655 Trust: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> (cherry picked from commit 0fca8a8) Reviewed-on: https://go-review.googlesource.com/c/go/+/394655 Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
Bump go to 1.18.1 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Signed-off-by: Noel Georgi <git@frezbo.dev>
Bump go to 1.17.9 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Signed-off-by: Noel Georgi <git@frezbo.dev>
Bump go to 1.17.9 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Update zlib download url's to use proper ones Signed-off-by: Noel Georgi <git@frezbo.dev>
Bump go to 1.17.9 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Update zlib download url's to use proper ones Signed-off-by: Noel Georgi <git@frezbo.dev>
Bump go to 1.18.1 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Also update zlib download url's Signed-off-by: Noel Georgi <git@frezbo.dev>
Bump go to 1.18.1 Fixes: - [CVE-2022-24675](golang/go#51853) - [CVE-2022-28327](golang/go#52075) - [CVE-2022-27536](golang/go#51759) Also update zlib download url's Signed-off-by: Noel Georgi <git@frezbo.dev>
On macOS, on an M1 Mac running macOS 12.3 and Go 1.18,
crypto/x509.(*Certificate).Verify
crashes:/cc @rolandshoemaker @FiloSottile @ianlancetaylor @josharian
The text was updated successfully, but these errors were encountered: