mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
crypto: essiv - Check ssize for decryption and in-place encryption
[ Upstream commit6bb73db694] Move the ssize check to the start in essiv_aead_crypt so that it's also checked for decryption and in-place encryption. Reported-by: Muhammad Alifa Ramdhan <ramdhan@starlabs.sg> Fixes:be1eb7f78a("crypto: essiv - create wrapper template for ESSIV generation") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
a794af4843
commit
dc4c854a5e
@@ -186,9 +186,14 @@ static int essiv_aead_crypt(struct aead_request *req, bool enc)
|
|||||||
const struct essiv_tfm_ctx *tctx = crypto_aead_ctx(tfm);
|
const struct essiv_tfm_ctx *tctx = crypto_aead_ctx(tfm);
|
||||||
struct essiv_aead_request_ctx *rctx = aead_request_ctx(req);
|
struct essiv_aead_request_ctx *rctx = aead_request_ctx(req);
|
||||||
struct aead_request *subreq = &rctx->aead_req;
|
struct aead_request *subreq = &rctx->aead_req;
|
||||||
|
int ivsize = crypto_aead_ivsize(tfm);
|
||||||
|
int ssize = req->assoclen - ivsize;
|
||||||
struct scatterlist *src = req->src;
|
struct scatterlist *src = req->src;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (ssize < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
crypto_cipher_encrypt_one(tctx->essiv_cipher, req->iv, req->iv);
|
crypto_cipher_encrypt_one(tctx->essiv_cipher, req->iv, req->iv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -198,19 +203,12 @@ static int essiv_aead_crypt(struct aead_request *req, bool enc)
|
|||||||
*/
|
*/
|
||||||
rctx->assoc = NULL;
|
rctx->assoc = NULL;
|
||||||
if (req->src == req->dst || !enc) {
|
if (req->src == req->dst || !enc) {
|
||||||
scatterwalk_map_and_copy(req->iv, req->dst,
|
scatterwalk_map_and_copy(req->iv, req->dst, ssize, ivsize, 1);
|
||||||
req->assoclen - crypto_aead_ivsize(tfm),
|
|
||||||
crypto_aead_ivsize(tfm), 1);
|
|
||||||
} else {
|
} else {
|
||||||
u8 *iv = (u8 *)aead_request_ctx(req) + tctx->ivoffset;
|
u8 *iv = (u8 *)aead_request_ctx(req) + tctx->ivoffset;
|
||||||
int ivsize = crypto_aead_ivsize(tfm);
|
|
||||||
int ssize = req->assoclen - ivsize;
|
|
||||||
struct scatterlist *sg;
|
struct scatterlist *sg;
|
||||||
int nents;
|
int nents;
|
||||||
|
|
||||||
if (ssize < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
nents = sg_nents_for_len(req->src, ssize);
|
nents = sg_nents_for_len(req->src, ssize);
|
||||||
if (nents < 0)
|
if (nents < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|||||||
Reference in New Issue
Block a user