Skip to contentSkip to conversation

crypto: gcm - Fix IV buffer size in crypto_gcm_setkey

PATCH In review Ondrej Mosnacek 2 participants 2 messages Sep 23, 2016 – Oct 2, 2016 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 crypto: gcm - Fix IV buffer size in crypto_gcm_setkey

The cipher block size for GCM is 16 bytes, and thus the CTR transform used in crypto_gcm_setkey() will also expect a 16-byte IV. However, the code currently reserves only 8 bytes for the IV, causing an out-of-bounds access in the CTR transform. This patch fixes the issue by setting the size of the IV buffer to 16 bytes.

Fixes 84c911523020 ("[CRYPTO] gcm: Add support for async ciphers")

---
(Sorry for previous broken patch, hopefully I got it right this time.)

I randomly noticed this while going over igcm.c for an unrelated reason. It seems the wrong buffer size never caused any noticeable problems (it's been there since 2007), but it should be corrected nonetheless...

 crypto/gcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/gcm.c +1 -1
index 70a892e8..f624ac9 100644
@@ -117,7 +117,7 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
 	struct crypto_skcipher *ctr = ctx->ctr;
 	struct {
 		be128 hash;
-		u8 iv[8];
+		u8 iv[16];
 
 		struct crypto_gcm_setkey_result result;
 

--
2.7.4

maintainer
#1 lore raw
Quoted 8 lines · Ondrej Mosnacek

The cipher block size for GCM is 16 bytes, and thus the CTR transform used in crypto_gcm_setkey() will also expect a 16-byte IV. However, the code currently reserves only 8 bytes for the IV, causing an out-of-bounds access in the CTR transform. This patch fixes the issue by setting the size of the IV buffer to 16 bytes.

Fixes 84c911523020 ("[CRYPTO] gcm: Add support for async ciphers")

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt