0014-v5.7-crypto-qce-use-cryptlen-when-adding-extra-sgl.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From d6364b8128439a8c0e381f80c38667de9f15eef8 Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <[email protected]>
  3. Date: Fri, 7 Feb 2020 12:02:25 -0300
  4. Subject: [PATCH 09/11] crypto: qce - use cryptlen when adding extra sgl
  5. The qce crypto driver appends an extra entry to the dst sgl, to maintain
  6. private state information.
  7. When the gcm driver sends requests to the ctr skcipher, it passes the
  8. authentication tag after the actual crypto payload, but it must not be
  9. touched.
  10. Commit 1336c2221bee ("crypto: qce - save a sg table slot for result
  11. buf") limited the destination sgl to avoid overwriting the
  12. authentication tag but it assumed the tag would be in a separate sgl
  13. entry.
  14. This is not always the case, so it is better to limit the length of the
  15. destination buffer to req->cryptlen before appending the result buf.
  16. Signed-off-by: Eneas U de Queiroz <[email protected]>
  17. Signed-off-by: Herbert Xu <[email protected]>
  18. ---
  19. drivers/crypto/qce/dma.c | 11 ++++++-----
  20. drivers/crypto/qce/dma.h | 2 +-
  21. drivers/crypto/qce/skcipher.c | 5 +++--
  22. 3 files changed, 10 insertions(+), 8 deletions(-)
  23. --- a/drivers/crypto/qce/dma.c
  24. +++ b/drivers/crypto/qce/dma.c
  25. @@ -48,9 +48,10 @@ void qce_dma_release(struct qce_dma_data
  26. struct scatterlist *
  27. qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl,
  28. - int max_ents)
  29. + unsigned int max_len)
  30. {
  31. struct scatterlist *sg = sgt->sgl, *sg_last = NULL;
  32. + unsigned int new_len;
  33. while (sg) {
  34. if (!sg_page(sg))
  35. @@ -61,13 +62,13 @@ qce_sgtable_add(struct sg_table *sgt, st
  36. if (!sg)
  37. return ERR_PTR(-EINVAL);
  38. - while (new_sgl && sg && max_ents) {
  39. - sg_set_page(sg, sg_page(new_sgl), new_sgl->length,
  40. - new_sgl->offset);
  41. + while (new_sgl && sg && max_len) {
  42. + new_len = new_sgl->length > max_len ? max_len : new_sgl->length;
  43. + sg_set_page(sg, sg_page(new_sgl), new_len, new_sgl->offset);
  44. sg_last = sg;
  45. sg = sg_next(sg);
  46. new_sgl = sg_next(new_sgl);
  47. - max_ents--;
  48. + max_len -= new_len;
  49. }
  50. return sg_last;
  51. --- a/drivers/crypto/qce/dma.h
  52. +++ b/drivers/crypto/qce/dma.h
  53. @@ -43,6 +43,6 @@ void qce_dma_issue_pending(struct qce_dm
  54. int qce_dma_terminate_all(struct qce_dma_data *dma);
  55. struct scatterlist *
  56. qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add,
  57. - int max_ents);
  58. + unsigned int max_len);
  59. #endif /* _DMA_H_ */
  60. --- a/drivers/crypto/qce/skcipher.c
  61. +++ b/drivers/crypto/qce/skcipher.c
  62. @@ -97,13 +97,14 @@ qce_skcipher_async_req_handle(struct cry
  63. sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
  64. - sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, rctx->dst_nents - 1);
  65. + sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, req->cryptlen);
  66. if (IS_ERR(sg)) {
  67. ret = PTR_ERR(sg);
  68. goto error_free;
  69. }
  70. - sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg, 1);
  71. + sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg,
  72. + QCE_RESULT_BUF_SZ);
  73. if (IS_ERR(sg)) {
  74. ret = PTR_ERR(sg);
  75. goto error_free;