Skip to content

Commit ebf533a

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: ccm - Remove VLA usage
In the quest to remove all stack VLA usage from the kernel[1], this drops AHASH_REQUEST_ON_STACK by preallocating the ahash request area combined with the skcipher area (which are not used at the same time). [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent d73d67f commit ebf533a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crypto/ccm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ struct crypto_ccm_req_priv_ctx {
5050
u32 flags;
5151
struct scatterlist src[3];
5252
struct scatterlist dst[3];
53-
struct skcipher_request skreq;
53+
union {
54+
struct ahash_request ahreq;
55+
struct skcipher_request skreq;
56+
};
5457
};
5558

5659
struct cbcmac_tfm_ctx {
@@ -181,7 +184,7 @@ static int crypto_ccm_auth(struct aead_request *req, struct scatterlist *plain,
181184
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
182185
struct crypto_aead *aead = crypto_aead_reqtfm(req);
183186
struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
184-
AHASH_REQUEST_ON_STACK(ahreq, ctx->mac);
187+
struct ahash_request *ahreq = &pctx->ahreq;
185188
unsigned int assoclen = req->assoclen;
186189
struct scatterlist sg[3];
187190
u8 *odata = pctx->odata;
@@ -427,7 +430,7 @@ static int crypto_ccm_init_tfm(struct crypto_aead *tfm)
427430
crypto_aead_set_reqsize(
428431
tfm,
429432
align + sizeof(struct crypto_ccm_req_priv_ctx) +
430-
crypto_skcipher_reqsize(ctr));
433+
max(crypto_ahash_reqsize(mac), crypto_skcipher_reqsize(ctr)));
431434

432435
return 0;
433436

0 commit comments

Comments
 (0)