aboutsummaryrefslogtreecommitdiff
path: root/ssh/cipher.go
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2021-11-09 11:45:57 -0800
committerRoland Shoemaker <roland@golang.org>2021-12-02 19:23:23 +0000
commit5770296d904e90f15f38f77dfc2e43fdf5efc083 (patch)
tree75fd3358961f563865bd18f66c721ede33ddf587 /ssh/cipher.go
parentae814b36b87190c757eede9bc2d32ed77df88551 (diff)
downloadgo-x-crypto-5770296d904e90f15f38f77dfc2e43fdf5efc083.tar.xz
ssh: don't assume packet plaintext size
When reading GCM and ChaChaPoly1305 packets, don't make assumptions about the size of the enciphered plaintext. This fixes two panics caused by standards non-compliant malformed packets. Thanks to Rod Hynes, Psiphon Inc. for reporting this issue. Fixes golang/go#49932 Fixes CVE-2021-43565 Change-Id: I660cff39d197e0d04ec44d11d792b22d954df2ef Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1262659 Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> Reviewed-on: https://go-review.googlesource.com/c/crypto/+/368814 Trust: Roland Shoemaker <roland@golang.org> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Julie Qiu <julie@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
Diffstat (limited to 'ssh/cipher.go')
-rw-r--r--ssh/cipher.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/ssh/cipher.go b/ssh/cipher.go
index bddbde5..f8bdf49 100644
--- a/ssh/cipher.go
+++ b/ssh/cipher.go
@@ -394,6 +394,10 @@ func (c *gcmCipher) readCipherPacket(seqNum uint32, r io.Reader) ([]byte, error)
}
c.incIV()
+ if len(plain) == 0 {
+ return nil, errors.New("ssh: empty packet")
+ }
+
padding := plain[0]
if padding < 4 {
// padding is a byte, so it automatically satisfies
@@ -710,6 +714,10 @@ func (c *chacha20Poly1305Cipher) readCipherPacket(seqNum uint32, r io.Reader) ([
plain := c.buf[4:contentEnd]
s.XORKeyStream(plain, plain)
+ if len(plain) == 0 {
+ return nil, errors.New("ssh: empty packet")
+ }
+
padding := plain[0]
if padding < 4 {
// padding is a byte, so it automatically satisfies