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

JIRA: https://issues.redhat.com/browse/RHEL-118175
Tested: compile only

commit 50fdb78b7c0bcc550910ef69c0984e751cac72fa
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Wed Dec 17 14:15:41 2025 +0800

    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: 0a270321db ("[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>

Signed-off-by: Xin Long <lxin@redhat.com>
This commit is contained in:
Xin Long
2025-12-31 15:50:16 -05:00
parent 4ba19846a8
commit f35b880e4e
+5 -3
View File
@@ -51,6 +51,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv); struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
struct aead_request *subreq = aead_request_ctx(req); struct aead_request *subreq = aead_request_ctx(req);
crypto_completion_t compl; crypto_completion_t compl;
bool unaligned_info;
void *data; void *data;
u8 *info; u8 *info;
unsigned int ivsize = 8; unsigned int ivsize = 8;
@@ -80,8 +81,9 @@ static int seqiv_aead_encrypt(struct aead_request *req)
return err; return err;
} }
if (unlikely(!IS_ALIGNED((unsigned long)info, unaligned_info = !IS_ALIGNED((unsigned long)info,
crypto_aead_alignmask(geniv) + 1))) { crypto_aead_alignmask(geniv) + 1);
if (unlikely(unaligned_info)) {
info = kmemdup(req->iv, ivsize, req->base.flags & info = kmemdup(req->iv, ivsize, req->base.flags &
CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
GFP_ATOMIC); GFP_ATOMIC);
@@ -101,7 +103,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1); scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1);
err = crypto_aead_encrypt(subreq); err = crypto_aead_encrypt(subreq);
if (unlikely(info != req->iv)) if (unlikely(unaligned_info))
seqiv_aead_encrypt_complete2(req, err); seqiv_aead_encrypt_complete2(req, err);
return err; return err;
} }