Skip to content

Commit 978e45a

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 993a314 commit 978e45a

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
@@ -499,14 +499,13 @@ static int atmel_tdes_crypt_start(struct atmel_tdes_dev *dd)
499499
IS_ALIGNED(dd->out_sg->length, dd->ctx->block_size);
500500
fast = in && out;
501501

502-
if (sg_dma_len(dd->in_sg) != sg_dma_len(dd->out_sg))
502+
if (dd->in_sg->length != dd->out_sg->length)
503503
fast = 0;
504504
}
505505

506506

507507
if (fast) {
508-
count = min_t(size_t, dd->total, sg_dma_len(dd->in_sg));
509-
count = min_t(size_t, count, sg_dma_len(dd->out_sg));
508+
count = min_t(size_t, dd->total, dd->in_sg->length);
510509

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

0 commit comments

Comments
 (0)