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

crypto: x86/aes-ni - add missing error checks in XTS code

The updated XTS code fails to check the return code of skcipher_walk_virt,
which may lead to skcipher_walk_abort() or skcipher_walk_done() being called
while the walk argument is in an inconsistent state.

So check the return value after each such call, and bail on errors.

Fixes: 2481104fe98d ("crypto: x86/aes-ni-xts - rewrite and drop indirections via glue helper")
Reported-by: Dave Hansen <dave.hansen@intel.com>
Reported-by: syzbot <syzbot+5d1bad8042a8f0e8117a@syzkaller.appspotmail.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
821720b9 f03a3cab

+5
+5
arch/x86/crypto/aesni-intel_glue.c
··· 849 849 return -EINVAL; 850 850 851 851 err = skcipher_walk_virt(&walk, req, false); 852 + if (err) 853 + return err; 852 854 853 855 if (unlikely(tail > 0 && walk.nbytes < walk.total)) { 854 856 int blocks = DIV_ROUND_UP(req->cryptlen, AES_BLOCK_SIZE) - 2; ··· 864 862 skcipher_request_set_crypt(&subreq, req->src, req->dst, 865 863 blocks * AES_BLOCK_SIZE, req->iv); 866 864 req = &subreq; 865 + 867 866 err = skcipher_walk_virt(&walk, req, false); 867 + if (err) 868 + return err; 868 869 } else { 869 870 tail = 0; 870 871 }