Limit the size of various MAXCHUNK definitions
authorPauli <pauli@openssl.org>
Mon, 15 Aug 2022 04:49:17 +0000 (14:49 +1000)
committerPauli <pauli@openssl.org>
Fri, 19 Aug 2022 07:29:48 +0000 (17:29 +1000)
The current code has issues when sizeof(long) <> sizeof(size_t).  The two
types are assumed to be interchangeable and them being different will
cause crashes and endless loops.

This fix limits the maximum chunk size for many of the symmetric ciphers
to 2^30 bytes.  This chunk size limits the amount of data that will
be encrypted/decrypted in one lump.  The code internally handles block
of data later than the chunk limit, so this will present no difference
to the caller.  Any loss of efficiency due to limiting the chunking to
1Gbyte rather than more should be insignificant.

Fixes Coverity issues:
    15084981508500 - 15085051508507 - 15085271508529 - 1508533,
    1508535 - 150853715085391508541 - 15085491508551 - 1508569 &
    1508571 - 1508582.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18997)

(cherry picked from commit 709d4be78f64a8ba0707fb5682b90039e848dad4)

include/crypto/evp.h
providers/implementations/include/prov/ciphercommon.h

index eeac4ee9f1174504c489301c62959a924199677b..e571c546c68332a9e8b31d75556d92f723e32872 100644 (file)
@@ -365,7 +365,7 @@ static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const uns
         return 1;\
 }
 
-#define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
+#define EVP_MAXCHUNK ((size_t)1 << 30)
 
 #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
     static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
index 91c4c914beb9c65b6cf68e921d49507869f2bda6..30a59e55729bac4e393b2870a48e49c1b7405028 100644 (file)
@@ -14,8 +14,8 @@
 #include "internal/cryptlib.h"
 #include "crypto/modes.h"
 
-#define MAXCHUNK    ((size_t)1 << (sizeof(long) * 8 - 2))
-#define MAXBITCHUNK ((size_t)1 << (sizeof(size_t) * 8 - 4))
+# define MAXCHUNK    ((size_t)1 << 30)
+# define MAXBITCHUNK ((size_t)1 << (sizeof(size_t) * 8 - 4))
 
 #define GENERIC_BLOCK_SIZE 16
 #define IV_STATE_UNINITIALISED 0  /* initial state is not initialized */