]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: seqiv - Do not use req->iv after crypto_aead_encrypt
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 17 Dec 2025 06:15:41 +0000 (14:15 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 19 Dec 2025 06:47:06 +0000 (14:47 +0800)
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>
crypto/seqiv.c

index 2bae99e3352683285c9d57cd530286631e9db732..678bb4145d783a5a7e81568290be62785af32159 100644 (file)
@@ -50,6 +50,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
        struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
        struct aead_request *subreq = aead_request_ctx(req);
        crypto_completion_t compl;
+       bool unaligned_info;
        void *data;
        u8 *info;
        unsigned int ivsize = 8;
@@ -68,8 +69,9 @@ static int seqiv_aead_encrypt(struct aead_request *req)
                memcpy_sglist(req->dst, req->src,
                              req->assoclen + req->cryptlen);
 
-       if (unlikely(!IS_ALIGNED((unsigned long)info,
-                                crypto_aead_alignmask(geniv) + 1))) {
+       unaligned_info = !IS_ALIGNED((unsigned long)info,
+                                    crypto_aead_alignmask(geniv) + 1);
+       if (unlikely(unaligned_info)) {
                info = kmemdup(req->iv, ivsize, req->base.flags &
                               CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
                               GFP_ATOMIC);
@@ -89,7 +91,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
        scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1);
 
        err = crypto_aead_encrypt(subreq);
-       if (unlikely(info != req->iv))
+       if (unlikely(unaligned_info))
                seqiv_aead_encrypt_complete2(req, err);
        return err;
 }