Skip to content

Commit ec9f200

Browse files
committed
crypto: cryptd - Fix AEAD request context corruption
The AEAD version of cryptd uses the same context for its own state as well as that of the child. In doing so it did not maintain the proper ordering, thus resulting in potential state corruption where the child will overwrite the state stored by cryptd. This patch fixes and also sets the request size properly. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 4d666db commit ec9f200

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎crypto/cryptd.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,18 @@ static void cryptd_aead_crypt(struct aead_request *req,
688688
int (*crypt)(struct aead_request *req))
689689
{
690690
struct cryptd_aead_request_ctx *rctx;
691+
crypto_completion_t compl;
692+
691693
rctx = aead_request_ctx(req);
694+
compl = rctx->complete;
692695

693696
if (unlikely(err == -EINPROGRESS))
694697
goto out;
695698
aead_request_set_tfm(req, child);
696699
err = crypt( req );
697-
req->base.complete = rctx->complete;
698700
out:
699701
local_bh_disable();
700-
rctx->complete(&req->base, err);
702+
compl(&req->base, err);
701703
local_bh_enable();
702704
}
703705

@@ -756,7 +758,9 @@ static int cryptd_aead_init_tfm(struct crypto_aead *tfm)
756758
return PTR_ERR(cipher);
757759

758760
ctx->child = cipher;
759-
crypto_aead_set_reqsize(tfm, sizeof(struct cryptd_aead_request_ctx));
761+
crypto_aead_set_reqsize(
762+
tfm, max((unsigned)sizeof(struct cryptd_aead_request_ctx),
763+
crypto_aead_reqsize(cipher)));
760764
return 0;
761765
}
762766

@@ -775,7 +779,7 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
775779
struct aead_alg *alg;
776780
const char *name;
777781
u32 type = 0;
778-
u32 mask = 0;
782+
u32 mask = CRYPTO_ALG_ASYNC;
779783
int err;
780784

781785
cryptd_check_internal(tb, &type, &mask);

0 commit comments

Comments
 (0)