Skip to content

Commit 302ecd1

Browse files
tobluxgregkh
authored andcommitted
crypto: atmel-tdes - use scatterlist length before DMA mapping
commit ba199bd upstream. Using sg_dma_len() is only valid after mapping the scatterlist with dma_map_sg(). However, atmel_tdes_crypt_start() uses it before mapping to compare input/output lengths and to compute the transfer count. Use the original scatterlist lengths before DMA mapping to avoid reading stale or uninitialized DMA lengths when CONFIG_NEED_SG_DMA_LENGTH=y. Drop the output scatterlist length in the fast path since it is equal to ->in_sg->length and does not change the transfer count. Fixes: 1380200 ("crypto: atmel - add Atmel DES/TDES driver") Fixes: 1f85804 ("crypto: atmel-tdes - add support for latest release of the IP (0x700)") Cc: stable@vger.kernel.org Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4c00183 commit 302ecd1

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/crypto/atmel-tdes.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,13 @@ static int atmel_tdes_crypt_start(struct atmel_tdes_dev *dd)
463463
IS_ALIGNED(dd->out_sg->length, dd->ctx->block_size);
464464
fast = in && out;
465465

466-
if (sg_dma_len(dd->in_sg) != sg_dma_len(dd->out_sg))
466+
if (dd->in_sg->length != dd->out_sg->length)
467467
fast = 0;
468468
}
469469

470470

471471
if (fast) {
472-
count = min_t(size_t, dd->total, sg_dma_len(dd->in_sg));
473-
count = min_t(size_t, count, sg_dma_len(dd->out_sg));
472+
count = min_t(size_t, dd->total, dd->in_sg->length);
474473

475474
err = dma_map_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
476475
if (!err) {

0 commit comments

Comments
 (0)