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

Configure Feed

Select the types of activity you want to include in your feed.

crypto: seqiv - Do not use req->iv after crypto_aead_encrypt

As soon as crypto_aead_encrypt is called, the underlying request
may be freed by an asynchronous completion. Thus dereferencing
req->iv after it returns is invalid.

Instead of checking req->iv against info, create a new variable
unaligned_info and use it for that purpose instead.

Fixes: 0a270321dbf9 ("[CRYPTO] seqiv: Add Sequence Number IV Generator")
Reported-by: Xiumei Mu <xmu@redhat.com>
Reported-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+5 -3
+5 -3
crypto/seqiv.c
··· 50 50 struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv); 51 51 struct aead_request *subreq = aead_request_ctx(req); 52 52 crypto_completion_t compl; 53 + bool unaligned_info; 53 54 void *data; 54 55 u8 *info; 55 56 unsigned int ivsize = 8; ··· 69 68 memcpy_sglist(req->dst, req->src, 70 69 req->assoclen + req->cryptlen); 71 70 72 - if (unlikely(!IS_ALIGNED((unsigned long)info, 73 - crypto_aead_alignmask(geniv) + 1))) { 71 + unaligned_info = !IS_ALIGNED((unsigned long)info, 72 + crypto_aead_alignmask(geniv) + 1); 73 + if (unlikely(unaligned_info)) { 74 74 info = kmemdup(req->iv, ivsize, req->base.flags & 75 75 CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : 76 76 GFP_ATOMIC); ··· 91 89 scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1); 92 90 93 91 err = crypto_aead_encrypt(subreq); 94 - if (unlikely(info != req->iv)) 92 + if (unlikely(unaligned_info)) 95 93 seqiv_aead_encrypt_complete2(req, err); 96 94 return err; 97 95 }