Commit b0356b75 authored by Herbert Xu's avatar Herbert Xu
Browse files

crypto: ahash - Fix crypto_ahash_import with partial block data



Restore the partial block buffer in crypto_ahash_import by copying
it.  Check whether the partial block buffer exceeds the maximum
size and return -EOVERFLOW if it does.

Zero the partial block buffer in crypto_ahash_import_core.

Reported-by: default avatarT Pratham <t-pratham@ti.com>
Tested-by: default avatarT Pratham <t-pratham@ti.com>
Fixes: 9d7a0ab1 ("crypto: ahash - Handle partial blocks in API")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 80b61046
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -661,6 +661,12 @@ int crypto_ahash_import_core(struct ahash_request *req, const void *in)
						in);
	if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
		return -ENOKEY;
	if (crypto_ahash_block_only(tfm)) {
		unsigned int reqsize = crypto_ahash_reqsize(tfm);
		u8 *buf = ahash_request_ctx(req);

		buf[reqsize - 1] = 0;
	}
	return crypto_ahash_alg(tfm)->import_core(req, in);
}
EXPORT_SYMBOL_GPL(crypto_ahash_import_core);
@@ -674,10 +680,14 @@ int crypto_ahash_import(struct ahash_request *req, const void *in)
	if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
		return -ENOKEY;
	if (crypto_ahash_block_only(tfm)) {
		unsigned int plen = crypto_ahash_blocksize(tfm) + 1;
		unsigned int reqsize = crypto_ahash_reqsize(tfm);
		unsigned int ss = crypto_ahash_statesize(tfm);
		u8 *buf = ahash_request_ctx(req);

		buf[reqsize - 1] = 0;
		memcpy(buf + reqsize - plen, in + ss - plen, plen);
		if (buf[reqsize - 1] >= plen)
			return -EOVERFLOW;
	}
	return crypto_ahash_alg(tfm)->import(req, in);
}