mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 06:31:49 +00:00
crypto: caam - handle zero-length AEAD output
Recent AEAD changes in testmgr framework introduced by commit
a0d608ee5e
("crypto: testmgr - unify the AEAD encryption and decryption test vectors")
uncovered an error in the CAAM drivers, since they don't correctly
handle the case when AEAD output length is zero.
Add checks to avoid feeding zero-length req->dst to DMA API.
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
87870cfb4b
commit
763069ba49
@ -846,6 +846,7 @@ static void caam_unmap(struct device *dev, struct scatterlist *src,
|
||||
if (dst != src) {
|
||||
if (src_nents)
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
|
||||
if (dst_nents)
|
||||
dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
|
||||
} else {
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
|
||||
@ -1038,7 +1039,9 @@ static void init_aead_job(struct aead_request *req,
|
||||
out_options = in_options;
|
||||
|
||||
if (unlikely(req->src != req->dst)) {
|
||||
if (edesc->dst_nents == 1) {
|
||||
if (!edesc->dst_nents) {
|
||||
dst_dma = 0;
|
||||
} else if (edesc->dst_nents == 1) {
|
||||
dst_dma = sg_dma_address(req->dst);
|
||||
} else {
|
||||
dst_dma = edesc->sec4_sg_dma +
|
||||
@ -1289,13 +1292,20 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
|
||||
mapped_src_nents = 0;
|
||||
}
|
||||
|
||||
mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
|
||||
/* Cover also the case of null (zero length) output data */
|
||||
if (dst_nents) {
|
||||
mapped_dst_nents = dma_map_sg(jrdev, req->dst,
|
||||
dst_nents,
|
||||
DMA_FROM_DEVICE);
|
||||
if (unlikely(!mapped_dst_nents)) {
|
||||
dev_err(jrdev, "unable to map destination\n");
|
||||
dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
|
||||
dma_unmap_sg(jrdev, req->src, src_nents,
|
||||
DMA_TO_DEVICE);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
} else {
|
||||
mapped_dst_nents = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
|
||||
|
@ -802,6 +802,7 @@ static void caam_unmap(struct device *dev, struct scatterlist *src,
|
||||
if (dst != src) {
|
||||
if (src_nents)
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
|
||||
if (dst_nents)
|
||||
dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
|
||||
} else {
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
|
||||
@ -955,14 +956,20 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
|
||||
mapped_src_nents = 0;
|
||||
}
|
||||
|
||||
mapped_dst_nents = dma_map_sg(qidev, req->dst, dst_nents,
|
||||
if (dst_nents) {
|
||||
mapped_dst_nents = dma_map_sg(qidev, req->dst,
|
||||
dst_nents,
|
||||
DMA_FROM_DEVICE);
|
||||
if (unlikely(!mapped_dst_nents)) {
|
||||
dev_err(qidev, "unable to map destination\n");
|
||||
dma_unmap_sg(qidev, req->src, src_nents, DMA_TO_DEVICE);
|
||||
dma_unmap_sg(qidev, req->src, src_nents,
|
||||
DMA_TO_DEVICE);
|
||||
qi_cache_free(edesc);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
} else {
|
||||
mapped_dst_nents = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((alg->caam.rfc3686 && encrypt) || !alg->caam.geniv)
|
||||
|
@ -144,6 +144,7 @@ static void caam_unmap(struct device *dev, struct scatterlist *src,
|
||||
if (dst != src) {
|
||||
if (src_nents)
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
|
||||
if (dst_nents)
|
||||
dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
|
||||
} else {
|
||||
dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
|
||||
@ -385,14 +386,19 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
|
||||
mapped_src_nents = 0;
|
||||
}
|
||||
|
||||
if (dst_nents) {
|
||||
mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
|
||||
DMA_FROM_DEVICE);
|
||||
if (unlikely(!mapped_dst_nents)) {
|
||||
dev_err(dev, "unable to map destination\n");
|
||||
dma_unmap_sg(dev, req->src, src_nents, DMA_TO_DEVICE);
|
||||
dma_unmap_sg(dev, req->src, src_nents,
|
||||
DMA_TO_DEVICE);
|
||||
qi_cache_free(edesc);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
} else {
|
||||
mapped_dst_nents = 0;
|
||||
}
|
||||
} else {
|
||||
src_nents = sg_nents_for_len(req->src, req->assoclen +
|
||||
req->cryptlen +
|
||||
|
Loading…
Reference in New Issue
Block a user