Skip to contentSkip to conversation

crypto: aesni-intel - fix wrong kfree pointer

PATCH In review Milan Broz 2 participants 2 messages Jun 28, 2012 – Jul 11, 2012

Subsystems (2)
lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/1 crypto: aesni-intel - fix wrong kfree pointer

kfree(new_key_mem) in rfc4106_set_key() should be called on malloced pointer, not on aligned one, otherwise it can cause invalid pointer on free.

(Seen at least once when running tcrypt tests with debug kernel.)

---
 arch/x86/crypto/aesni-intel_glue.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/crypto/aesni-intel_glue.c +4 -4
index ac7f5cd..c9bac53 100644
@@ -613,7 +613,7 @@ static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
 	struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
 	struct aesni_rfc4106_gcm_ctx *child_ctx =
                                  aesni_rfc4106_gcm_ctx_get(cryptd_child);
-	u8 *new_key_mem = NULL;
+	u8 *new_key_align, *new_key_mem = NULL;
 
 	if (key_len < 4) {
 		crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
@@ -637,9 +637,9 @@ static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
 		if (!new_key_mem)
 			return -ENOMEM;
 
-		new_key_mem = PTR_ALIGN(new_key_mem, AESNI_ALIGN);
-		memcpy(new_key_mem, key, key_len);
-		key = new_key_mem;
+		new_key_align = PTR_ALIGN(new_key_mem, AESNI_ALIGN);
+		memcpy(new_key_align, key, key_len);
+		key = new_key_align;
 	}
 
 	if (!irq_fpu_usable())
Signature · 1 line
1.7.10
maintainer
#1 lore raw
Quoted 6 lines · Milan Broz

kfree(new_key_mem) in rfc4106_set_key() should be called on malloced pointer, not on aligned one, otherwise it can cause invalid pointer on free.

(Seen at least once when running tcrypt tests with debug kernel.)

Good catch. Patch applied.

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