Commit 5db6ef98 authored by Yucheng Lu's avatar Yucheng Lu Committed by Herbert Xu
Browse files

crypto: authencesn - reject short ahash digests during instance creation



authencesn requires either a zero authsize or an authsize of at least
4 bytes because the ESN encrypt/decrypt paths always move 4 bytes of
high-order sequence number data at the end of the authenticated data.

While crypto_authenc_esn_setauthsize() already rejects explicit
non-zero authsizes in the range 1..3, crypto_authenc_esn_create()
still copied auth->digestsize into inst->alg.maxauthsize without
validating it.  The AEAD core then initialized the tfm's default
authsize from that value.

As a result, selecting an ahash with digest size 1..3, such as
cbcmac(cipher_null), exposed authencesn instances whose default
authsize was invalid even though setauthsize() would have rejected the
same value.  AF_ALG could then trigger the ESN tail handling with a
too-short tag and hit an out-of-bounds access.

Reject authencesn instances whose ahash digest size is in the invalid
non-zero range 1..3 so that no tfm can inherit an unsupported default
authsize.

Fixes: f15f05b0 ("crypto: ccm - switch to separate cbcmac driver")
Cc: stable@kernel.org
Reported-by: default avatarYifan Wu <yifanwucs@gmail.com>
Reported-by: default avatarJuefei Pu <tomapufckgml@gmail.com>
Co-developed-by: default avatarYuan Tan <yuantan098@gmail.com>
Signed-off-by: default avatarYuan Tan <yuantan098@gmail.com>
Suggested-by: default avatarXin Liu <bird@lzu.edu.cn>
Tested-by: default avatarYuhang Zheng <z1652074432@gmail.com>
Reviewed-by: default avatarEric Biggers <ebiggers@kernel.org>
Signed-off-by: default avatarYucheng Lu <kanolyc@gmail.com>
Signed-off-by: default avatarRen Wei <n05ec@lzu.edu.cn>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3bfbf5f0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -390,6 +390,11 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl,
	auth = crypto_spawn_ahash_alg(&ctx->auth);
	auth_base = &auth->base;

	if (auth->digestsize > 0 && auth->digestsize < 4) {
		err = -EINVAL;
		goto err_free_inst;
	}

	err = crypto_grab_skcipher(&ctx->enc, aead_crypto_instance(inst),
				   crypto_attr_alg_name(tb[2]), 0, mask);
	if (err)