aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-04-25 12:32:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-04-25 12:32:45 -0400
commitbcc981e9ed84c678533299d7eff17d2c81e4d5de (patch)
treed5fa794057f941fdae90d1564b80c8f05ca888e9
parent02da2d72174c61988eb4456b53f405e3ebdebce4 (diff)
parent340ff60ae93a5db2b2be6f38868df9a1293b6007 (diff)
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: "This fixes a couple of regressions in the talitos driver that were introduced back in 4.3. The first bug causes a crash when the driver's AEAD functionality is used while the second bug prevents its AEAD feature from working once you get past the first bug" * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: talitos - fix AEAD tcrypt tests crypto: talitos - fix crash in talitos_cra_init()
-rw-r--r--drivers/crypto/talitos.c87
1 files changed, 57 insertions, 30 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index a0d4a08313ae..aae05547b924 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -63,6 +63,14 @@ static void to_talitos_ptr(struct talitos_ptr *ptr, dma_addr_t dma_addr,
63 ptr->eptr = upper_32_bits(dma_addr); 63 ptr->eptr = upper_32_bits(dma_addr);
64} 64}
65 65
66static void copy_talitos_ptr(struct talitos_ptr *dst_ptr,
67 struct talitos_ptr *src_ptr, bool is_sec1)
68{
69 dst_ptr->ptr = src_ptr->ptr;
70 if (!is_sec1)
71 dst_ptr->eptr = src_ptr->eptr;
72}
73
66static void to_talitos_ptr_len(struct talitos_ptr *ptr, unsigned int len, 74static void to_talitos_ptr_len(struct talitos_ptr *ptr, unsigned int len,
67 bool is_sec1) 75 bool is_sec1)
68{ 76{
@@ -1083,21 +1091,20 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1083 sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ?: 1, 1091 sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ?: 1,
1084 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL 1092 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
1085 : DMA_TO_DEVICE); 1093 : DMA_TO_DEVICE);
1086
1087 /* hmac data */ 1094 /* hmac data */
1088 desc->ptr[1].len = cpu_to_be16(areq->assoclen); 1095 desc->ptr[1].len = cpu_to_be16(areq->assoclen);
1089 if (sg_count > 1 && 1096 if (sg_count > 1 &&
1090 (ret = sg_to_link_tbl_offset(areq->src, sg_count, 0, 1097 (ret = sg_to_link_tbl_offset(areq->src, sg_count, 0,
1091 areq->assoclen, 1098 areq->assoclen,
1092 &edesc->link_tbl[tbl_off])) > 1) { 1099 &edesc->link_tbl[tbl_off])) > 1) {
1093 tbl_off += ret;
1094
1095 to_talitos_ptr(&desc->ptr[1], edesc->dma_link_tbl + tbl_off * 1100 to_talitos_ptr(&desc->ptr[1], edesc->dma_link_tbl + tbl_off *
1096 sizeof(struct talitos_ptr), 0); 1101 sizeof(struct talitos_ptr), 0);
1097 desc->ptr[1].j_extent = DESC_PTR_LNKTBL_JUMP; 1102 desc->ptr[1].j_extent = DESC_PTR_LNKTBL_JUMP;
1098 1103
1099 dma_sync_single_for_device(dev, edesc->dma_link_tbl, 1104 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
1100 edesc->dma_len, DMA_BIDIRECTIONAL); 1105 edesc->dma_len, DMA_BIDIRECTIONAL);
1106
1107 tbl_off += ret;
1101 } else { 1108 } else {
1102 to_talitos_ptr(&desc->ptr[1], sg_dma_address(areq->src), 0); 1109 to_talitos_ptr(&desc->ptr[1], sg_dma_address(areq->src), 0);
1103 desc->ptr[1].j_extent = 0; 1110 desc->ptr[1].j_extent = 0;
@@ -1126,11 +1133,13 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1126 if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV) 1133 if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
1127 sg_link_tbl_len += authsize; 1134 sg_link_tbl_len += authsize;
1128 1135
1129 if (sg_count > 1 && 1136 if (sg_count == 1) {
1130 (ret = sg_to_link_tbl_offset(areq->src, sg_count, areq->assoclen, 1137 to_talitos_ptr(&desc->ptr[4], sg_dma_address(areq->src) +
1131 sg_link_tbl_len, 1138 areq->assoclen, 0);
1132 &edesc->link_tbl[tbl_off])) > 1) { 1139 } else if ((ret = sg_to_link_tbl_offset(areq->src, sg_count,
1133 tbl_off += ret; 1140 areq->assoclen, sg_link_tbl_len,
1141 &edesc->link_tbl[tbl_off])) >
1142 1) {
1134 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP; 1143 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
1135 to_talitos_ptr(&desc->ptr[4], edesc->dma_link_tbl + 1144 to_talitos_ptr(&desc->ptr[4], edesc->dma_link_tbl +
1136 tbl_off * 1145 tbl_off *
@@ -1138,8 +1147,10 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1138 dma_sync_single_for_device(dev, edesc->dma_link_tbl, 1147 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
1139 edesc->dma_len, 1148 edesc->dma_len,
1140 DMA_BIDIRECTIONAL); 1149 DMA_BIDIRECTIONAL);
1141 } else 1150 tbl_off += ret;
1142 to_talitos_ptr(&desc->ptr[4], sg_dma_address(areq->src), 0); 1151 } else {
1152 copy_talitos_ptr(&desc->ptr[4], &edesc->link_tbl[tbl_off], 0);
1153 }
1143 1154
1144 /* cipher out */ 1155 /* cipher out */
1145 desc->ptr[5].len = cpu_to_be16(cryptlen); 1156 desc->ptr[5].len = cpu_to_be16(cryptlen);
@@ -1151,11 +1162,13 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1151 1162
1152 edesc->icv_ool = false; 1163 edesc->icv_ool = false;
1153 1164
1154 if (sg_count > 1 && 1165 if (sg_count == 1) {
1155 (sg_count = sg_to_link_tbl_offset(areq->dst, sg_count, 1166 to_talitos_ptr(&desc->ptr[5], sg_dma_address(areq->dst) +
1167 areq->assoclen, 0);
1168 } else if ((sg_count =
1169 sg_to_link_tbl_offset(areq->dst, sg_count,
1156 areq->assoclen, cryptlen, 1170 areq->assoclen, cryptlen,
1157 &edesc->link_tbl[tbl_off])) > 1171 &edesc->link_tbl[tbl_off])) > 1) {
1158 1) {
1159 struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off]; 1172 struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off];
1160 1173
1161 to_talitos_ptr(&desc->ptr[5], edesc->dma_link_tbl + 1174 to_talitos_ptr(&desc->ptr[5], edesc->dma_link_tbl +
@@ -1178,8 +1191,9 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1178 edesc->dma_len, DMA_BIDIRECTIONAL); 1191 edesc->dma_len, DMA_BIDIRECTIONAL);
1179 1192
1180 edesc->icv_ool = true; 1193 edesc->icv_ool = true;
1181 } else 1194 } else {
1182 to_talitos_ptr(&desc->ptr[5], sg_dma_address(areq->dst), 0); 1195 copy_talitos_ptr(&desc->ptr[5], &edesc->link_tbl[tbl_off], 0);
1196 }
1183 1197
1184 /* iv out */ 1198 /* iv out */
1185 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 1199 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv,
@@ -2629,21 +2643,11 @@ struct talitos_crypto_alg {
2629 struct talitos_alg_template algt; 2643 struct talitos_alg_template algt;
2630}; 2644};
2631 2645
2632static int talitos_cra_init(struct crypto_tfm *tfm) 2646static int talitos_init_common(struct talitos_ctx *ctx,
2647 struct talitos_crypto_alg *talitos_alg)
2633{ 2648{
2634 struct crypto_alg *alg = tfm->__crt_alg;
2635 struct talitos_crypto_alg *talitos_alg;
2636 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
2637 struct talitos_private *priv; 2649 struct talitos_private *priv;
2638 2650
2639 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH)
2640 talitos_alg = container_of(__crypto_ahash_alg(alg),
2641 struct talitos_crypto_alg,
2642 algt.alg.hash);
2643 else
2644 talitos_alg = container_of(alg, struct talitos_crypto_alg,
2645 algt.alg.crypto);
2646
2647 /* update context with ptr to dev */ 2651 /* update context with ptr to dev */
2648 ctx->dev = talitos_alg->dev; 2652 ctx->dev = talitos_alg->dev;
2649 2653
@@ -2661,10 +2665,33 @@ static int talitos_cra_init(struct crypto_tfm *tfm)
2661 return 0; 2665 return 0;
2662} 2666}
2663 2667
2668static int talitos_cra_init(struct crypto_tfm *tfm)
2669{
2670 struct crypto_alg *alg = tfm->__crt_alg;
2671 struct talitos_crypto_alg *talitos_alg;
2672 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
2673
2674 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH)
2675 talitos_alg = container_of(__crypto_ahash_alg(alg),
2676 struct talitos_crypto_alg,
2677 algt.alg.hash);
2678 else
2679 talitos_alg = container_of(alg, struct talitos_crypto_alg,
2680 algt.alg.crypto);
2681
2682 return talitos_init_common(ctx, talitos_alg);
2683}
2684
2664static int talitos_cra_init_aead(struct crypto_aead *tfm) 2685static int talitos_cra_init_aead(struct crypto_aead *tfm)
2665{ 2686{
2666 talitos_cra_init(crypto_aead_tfm(tfm)); 2687 struct aead_alg *alg = crypto_aead_alg(tfm);
2667 return 0; 2688 struct talitos_crypto_alg *talitos_alg;
2689 struct talitos_ctx *ctx = crypto_aead_ctx(tfm);
2690
2691 talitos_alg = container_of(alg, struct talitos_crypto_alg,
2692 algt.alg.aead);
2693
2694 return talitos_init_common(ctx, talitos_alg);
2668} 2695}
2669 2696
2670static int talitos_cra_init_ahash(struct crypto_tfm *tfm) 2697static int talitos_cra_init_ahash(struct crypto_tfm *tfm)