]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Handle zero length plaintext for VIA PadLock functions
authorMatthias-Christian Ott <ott@mirix.org>
Tue, 30 Dec 2014 09:57:36 +0000 (11:57 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 30 Dec 2014 09:57:36 +0000 (11:57 +0200)
If the plaintext is shorter than the block size of the used cipher,
_gnutls_auth_cipher_encrypt2_tag calls _gnutls_cipher_encrypt2 with
textlen = 0. padlock_ecb_encrypt and padlock_cbc_encrypt assume that the
plaintext length (last parameter) is greater than zero and segfault
otherwise. The assembler code for both functions is automatically
generated and imported from OpenSSL, so to ease maintenance the length
should be validated in the functions that call padlock_ecb_encrypt or
padlock_cbc_encrypt.

lib/accelerated/x86/aes-gcm-padlock.c
lib/accelerated/x86/aes-padlock.c

index e15afd4978c9d1b4108f67193614e9a0e03768a8..410cfc055fdd4f499f3f85db9240b03a1901ac07 100644 (file)
@@ -54,7 +54,8 @@ static void padlock_aes_encrypt(const void *_ctx,
 
        pce = ALIGN16(&ctx->expanded_key);
 
-       padlock_ecb_encrypt(dst, src, pce, length);
+       if (length > 0)
+               padlock_ecb_encrypt(dst, src, pce, length);
 }
 
 static void padlock_aes128_set_encrypt_key(struct padlock_ctx *_ctx,
index 58c42638a26775e2ef04dca38ca7bc701384307c..3e1c4f5a14fdaa66f8fd031d0e40f425f0cc2088 100644 (file)
@@ -132,7 +132,8 @@ padlock_aes_cbc_encrypt(void *_ctx, const void *src, size_t src_size,
 
        pce = ALIGN16(&ctx->expanded_key);
 
-       padlock_cbc_encrypt(dst, src, pce, src_size);
+       if (src_size > 0)
+               padlock_cbc_encrypt(dst, src, pce, src_size);
 
        return 0;
 }
@@ -147,7 +148,8 @@ padlock_aes_cbc_decrypt(void *_ctx, const void *src, size_t src_size,
 
        pcd = ALIGN16(&ctx->expanded_key);
 
-       padlock_cbc_encrypt(dst, src, pcd, src_size);
+       if (src_size > 0)
+               padlock_cbc_encrypt(dst, src, pcd, src_size);
 
        return 0;
 }