| From 13cc6f48c7434ce46ba6dbc90003a136a263d75a Mon Sep 17 00:00:00 2001 |
| From: =?UTF-8?q?Horia=20Geant=C4=83?= <horia.geanta@nxp.com> |
| Date: Fri, 14 Sep 2018 18:34:28 +0300 |
| Subject: crypto: caam/jr - fix ablkcipher_edesc pointer arithmetic |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| From: Horia Geantă <horia.geanta@nxp.com> |
| |
| commit 13cc6f48c7434ce46ba6dbc90003a136a263d75a upstream. |
| |
| In some cases the zero-length hw_desc array at the end of |
| ablkcipher_edesc struct requires for 4B of tail padding. |
| |
| Due to tail padding and the way pointers to S/G table and IV |
| are computed: |
| edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + |
| desc_bytes; |
| iv = (u8 *)edesc->hw_desc + desc_bytes + sec4_sg_bytes; |
| first 4 bytes of IV are overwritten by S/G table. |
| |
| Update computation of pointer to S/G table to rely on offset of hw_desc |
| member and not on sizeof() operator. |
| |
| Cc: <stable@vger.kernel.org> # 4.13+ |
| Fixes: 115957bb3e59 ("crypto: caam - fix IV DMA mapping and updating") |
| Signed-off-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> |
| |
| --- |
| drivers/crypto/caam/caamalg.c | 8 ++++---- |
| 1 file changed, 4 insertions(+), 4 deletions(-) |
| |
| --- a/drivers/crypto/caam/caamalg.c |
| +++ b/drivers/crypto/caam/caamalg.c |
| @@ -1511,8 +1511,8 @@ static struct ablkcipher_edesc *ablkciph |
| edesc->src_nents = src_nents; |
| edesc->dst_nents = dst_nents; |
| edesc->sec4_sg_bytes = sec4_sg_bytes; |
| - edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + |
| - desc_bytes; |
| + edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc + |
| + desc_bytes); |
| edesc->iv_dir = DMA_TO_DEVICE; |
| |
| /* Make sure IV is located in a DMAable area */ |
| @@ -1715,8 +1715,8 @@ static struct ablkcipher_edesc *ablkciph |
| edesc->src_nents = src_nents; |
| edesc->dst_nents = dst_nents; |
| edesc->sec4_sg_bytes = sec4_sg_bytes; |
| - edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + |
| - desc_bytes; |
| + edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc + |
| + desc_bytes); |
| edesc->iv_dir = DMA_FROM_DEVICE; |
| |
| /* Make sure IV is located in a DMAable area */ |