• Ard Biesheuvel's avatar
    crypto: qat - move temp buffers off the stack · cfa1d744
    Ard Biesheuvel authored
    Arnd reports that with Kees's latest VLA patches applied, the HMAC
    handling in the QAT driver uses a worst case estimate of 160 bytes
    for the SHA blocksize, allowing the compiler to determine the size
    of the stack frame at compile time and throw a warning:
    
      drivers/crypto/qat/qat_common/qat_algs.c: In function 'qat_alg_do_precomputes':
      drivers/crypto/qat/qat_common/qat_algs.c:257:1: error: the frame size
      of 1112 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
    
    Given that this worst case estimate is only 32 bytes larger than the
    actual block size of SHA-512, the use of a VLA here was hiding the
    excessive size of the stack frame from the compiler, and so we should
    try to move these buffers off the stack.
    
    So move the ipad/opad buffers and the various SHA state descriptors
    into the tfm context struct. Since qat_alg_do_precomputes() is only
    called in the context of a setkey() operation, this should be safe.
    Using SHA512_BLOCK_SIZE for the size of the ipad/opad buffers allows
    them to be used by SHA-1/SHA-256 as well.
    Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    cfa1d744
qat_algs.c 40.4 KB