Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: qat - Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this uses
the new upper bound for the stack buffer. Also adds a sanity check.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Kees Cook and committed by
Herbert Xu
1299c9cf a9f7f88a

+6 -2
+6 -2
drivers/crypto/qat/qat_common/qat_algs.c
··· 153 153 struct sha512_state sha512; 154 154 int block_size = crypto_shash_blocksize(ctx->hash_tfm); 155 155 int digest_size = crypto_shash_digestsize(ctx->hash_tfm); 156 - char ipad[block_size]; 157 - char opad[block_size]; 156 + char ipad[MAX_ALGAPI_BLOCKSIZE]; 157 + char opad[MAX_ALGAPI_BLOCKSIZE]; 158 158 __be32 *hash_state_out; 159 159 __be64 *hash512_state_out; 160 160 int i, offset; ··· 163 163 memset(opad, 0, block_size); 164 164 shash->tfm = ctx->hash_tfm; 165 165 shash->flags = 0x0; 166 + 167 + if (WARN_ON(block_size > sizeof(ipad) || 168 + sizeof(ipad) != sizeof(opad))) 169 + return -EINVAL; 166 170 167 171 if (auth_keylen > block_size) { 168 172 int ret = crypto_shash_digest(shash, auth_key,