Skip to content

Commit de78c6b

Browse files
Rosioru DragosLee Jones
authored andcommitted
crypto: mxs-dcp - fix scatterlist linearization for hash
commit fa03481 upstream. The incorrect traversal of the scatterlist, during the linearization phase lead to computing the hash value of the wrong input buffer. New implementation uses scatterwalk_map_and_copy() to address this issue. Cc: <stable@vger.kernel.org> Fixes: 15b59e7 ("crypto: mxs - Add Freescale MXS DCP driver") Signed-off-by: Rosioru Dragos <dragos.rosioru@nxp.com> Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Lee Jones <lee.jones@linaro.org> Change-Id: Iab0ed5ed04c8e2783ef585180ac02f4fd5d9f792
1 parent eee979d commit de78c6b

1 file changed

Lines changed: 28 additions & 30 deletions

File tree

drivers/crypto/mxs-dcp.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <crypto/aes.h>
2626
#include <crypto/sha.h>
2727
#include <crypto/internal/hash.h>
28+
#include <crypto/scatterwalk.h>
2829

2930
#define DCP_MAX_CHANS 4
3031
#define DCP_BUF_SZ PAGE_SIZE
@@ -626,49 +627,46 @@ static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
626627
struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
627628
struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
628629
struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
629-
const int nents = sg_nents(req->src);
630630

631631
uint8_t *in_buf = sdcp->coh->sha_in_buf;
632632
uint8_t *out_buf = sdcp->coh->sha_out_buf;
633633

634-
uint8_t *src_buf;
635-
636634
struct scatterlist *src;
637635

638-
unsigned int i, len, clen;
636+
unsigned int i, len, clen, oft = 0;
639637
int ret;
640638

641639
int fin = rctx->fini;
642640
if (fin)
643641
rctx->fini = 0;
644642

645-
for_each_sg(req->src, src, nents, i) {
646-
src_buf = sg_virt(src);
647-
len = sg_dma_len(src);
648-
649-
do {
650-
if (actx->fill + len > DCP_BUF_SZ)
651-
clen = DCP_BUF_SZ - actx->fill;
652-
else
653-
clen = len;
654-
655-
memcpy(in_buf + actx->fill, src_buf, clen);
656-
len -= clen;
657-
src_buf += clen;
658-
actx->fill += clen;
643+
src = req->src;
644+
len = req->nbytes;
659645

660-
/*
661-
* If we filled the buffer and still have some
662-
* more data, submit the buffer.
663-
*/
664-
if (len && actx->fill == DCP_BUF_SZ) {
665-
ret = mxs_dcp_run_sha(req);
666-
if (ret)
667-
return ret;
668-
actx->fill = 0;
669-
rctx->init = 0;
670-
}
671-
} while (len);
646+
while (len) {
647+
if (actx->fill + len > DCP_BUF_SZ)
648+
clen = DCP_BUF_SZ - actx->fill;
649+
else
650+
clen = len;
651+
652+
scatterwalk_map_and_copy(in_buf + actx->fill, src, oft, clen,
653+
0);
654+
655+
len -= clen;
656+
oft += clen;
657+
actx->fill += clen;
658+
659+
/*
660+
* If we filled the buffer and still have some
661+
* more data, submit the buffer.
662+
*/
663+
if (len && actx->fill == DCP_BUF_SZ) {
664+
ret = mxs_dcp_run_sha(req);
665+
if (ret)
666+
return ret;
667+
actx->fill = 0;
668+
rctx->init = 0;
669+
}
672670
}
673671

674672
if (fin) {

0 commit comments

Comments
 (0)