Skip to content

Commit 1e9c5bb

Browse files
committed
crypto/aes: add missing aes-gcm buffer overlap checks to PPC64
The tests added by CL 601778 highlighted missing buffer overlap checks in the ppc64 specific aes-gcm implementation. Fixes #69007 Change-Id: I80c3b5628c5079cfed2c3dace7298512c16a8f46 Reviewed-on: https://go-review.googlesource.com/c/go/+/607519 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 2cee5d8 commit 1e9c5bb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/crypto/aes/gcm_ppc64x.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package aes
88

99
import (
1010
"crypto/cipher"
11+
"crypto/internal/alias"
1112
"crypto/subtle"
1213
"errors"
1314
"internal/byteorder"
@@ -171,6 +172,9 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
171172
}
172173

173174
ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
175+
if alias.InexactOverlap(out[:len(plaintext)], plaintext) {
176+
panic("crypto/cipher: invalid buffer overlap")
177+
}
174178

175179
var counter, tagMask [gcmBlockSize]byte
176180
g.deriveCounter(&counter, nonce)
@@ -210,6 +214,9 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
210214
g.auth(expectedTag[:], ciphertext, data, &tagMask)
211215

212216
ret, out := sliceForAppend(dst, len(ciphertext))
217+
if alias.InexactOverlap(out, ciphertext) {
218+
panic("crypto/cipher: invalid buffer overlap")
219+
}
213220

214221
if subtle.ConstantTimeCompare(expectedTag[:g.tagSize], tag) != 1 {
215222
clear(out)

0 commit comments

Comments
 (0)