Skip to content

Commit 3bdd23f

Browse files
keesherbertx
authored andcommitted
crypto: xcbc - Remove VLA usage
In the quest to remove all stack VLA usage from the kernel[1], this uses the maximum blocksize and adds a sanity check. For xcbc, the blocksize must always be 16, so use that, since it's already being enforced during instantiation. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 578bdaa commit 3bdd23f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crypto/xcbc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ struct xcbc_desc_ctx {
5757
u8 ctx[];
5858
};
5959

60+
#define XCBC_BLOCKSIZE 16
61+
6062
static int crypto_xcbc_digest_setkey(struct crypto_shash *parent,
6163
const u8 *inkey, unsigned int keylen)
6264
{
6365
unsigned long alignmask = crypto_shash_alignmask(parent);
6466
struct xcbc_tfm_ctx *ctx = crypto_shash_ctx(parent);
65-
int bs = crypto_shash_blocksize(parent);
6667
u8 *consts = PTR_ALIGN(&ctx->ctx[0], alignmask + 1);
6768
int err = 0;
68-
u8 key1[bs];
69+
u8 key1[XCBC_BLOCKSIZE];
70+
int bs = sizeof(key1);
6971

7072
if ((err = crypto_cipher_setkey(ctx->child, inkey, keylen)))
7173
return err;
@@ -212,7 +214,7 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
212214
return PTR_ERR(alg);
213215

214216
switch(alg->cra_blocksize) {
215-
case 16:
217+
case XCBC_BLOCKSIZE:
216218
break;
217219
default:
218220
goto out_put_alg;

0 commit comments

Comments
 (0)