Skip to content

Commit 13cc6f4

Browse files
horiagherbertx
authored andcommitted
crypto: caam/jr - fix ablkcipher_edesc pointer arithmetic
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: 115957b ("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>
1 parent 24568b4 commit 13cc6f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,8 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
15531553
edesc->src_nents = src_nents;
15541554
edesc->dst_nents = dst_nents;
15551555
edesc->sec4_sg_bytes = sec4_sg_bytes;
1556-
edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
1557-
desc_bytes;
1556+
edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
1557+
desc_bytes);
15581558
edesc->iv_dir = DMA_TO_DEVICE;
15591559

15601560
/* Make sure IV is located in a DMAable area */
@@ -1757,8 +1757,8 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
17571757
edesc->src_nents = src_nents;
17581758
edesc->dst_nents = dst_nents;
17591759
edesc->sec4_sg_bytes = sec4_sg_bytes;
1760-
edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
1761-
desc_bytes;
1760+
edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
1761+
desc_bytes);
17621762
edesc->iv_dir = DMA_FROM_DEVICE;
17631763

17641764
/* Make sure IV is located in a DMAable area */

0 commit comments

Comments
 (0)