Skip to content

Commit 50fdb78

Browse files
committed
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: 0a27032 ("[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>
1 parent 8f0b4cc commit 50fdb78

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

crypto/seqiv.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
5050
struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
5151
struct aead_request *subreq = aead_request_ctx(req);
5252
crypto_completion_t compl;
53+
bool unaligned_info;
5354
void *data;
5455
u8 *info;
5556
unsigned int ivsize = 8;
@@ -68,8 +69,9 @@ static int seqiv_aead_encrypt(struct aead_request *req)
6869
memcpy_sglist(req->dst, req->src,
6970
req->assoclen + req->cryptlen);
7071

71-
if (unlikely(!IS_ALIGNED((unsigned long)info,
72-
crypto_aead_alignmask(geniv) + 1))) {
72+
unaligned_info = !IS_ALIGNED((unsigned long)info,
73+
crypto_aead_alignmask(geniv) + 1);
74+
if (unlikely(unaligned_info)) {
7375
info = kmemdup(req->iv, ivsize, req->base.flags &
7476
CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
7577
GFP_ATOMIC);
@@ -89,7 +91,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
8991
scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1);
9092

9193
err = crypto_aead_encrypt(subreq);
92-
if (unlikely(info != req->iv))
94+
if (unlikely(unaligned_info))
9395
seqiv_aead_encrypt_complete2(req, err);
9496
return err;
9597
}

0 commit comments

Comments
 (0)