Skip to content

Commit 63d9df9

Browse files
chleroygregkh
authored andcommitted
crypto: talitos - fix IPsec cipher in length
commit 2b12273 upstream. For SEC 2.x+, cipher in length must contain only the ciphertext length. In case of using hardware ICV checking, the ICV length is provided via the "extent" field of the descriptor pointer. Cc: <[email protected]> # 4.8+ Fixes: 549bd8b ("crypto: talitos - Implement AEAD for SEC1 using HMAC_SNOOP_NO_AFEU") Reported-by: Horia Geantă <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Tested-by: Horia Geantă <[email protected]> Signed-off-by: Herbert Xu <[email protected]> [backported to 4.9.y, 4.14.y] Signed-off-by: Horia Geantă <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e9caf1e commit 63d9df9

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

drivers/crypto/talitos.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,10 @@ static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count,
11161116
return count;
11171117
}
11181118

1119-
int talitos_sg_map(struct device *dev, struct scatterlist *src,
1120-
unsigned int len, struct talitos_edesc *edesc,
1121-
struct talitos_ptr *ptr,
1122-
int sg_count, unsigned int offset, int tbl_off)
1119+
static int talitos_sg_map_ext(struct device *dev, struct scatterlist *src,
1120+
unsigned int len, struct talitos_edesc *edesc,
1121+
struct talitos_ptr *ptr, int sg_count,
1122+
unsigned int offset, int tbl_off, int elen)
11231123
{
11241124
struct talitos_private *priv = dev_get_drvdata(dev);
11251125
bool is_sec1 = has_ftr_sec1(priv);
@@ -1130,7 +1130,7 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
11301130
}
11311131

11321132
to_talitos_ptr_len(ptr, len, is_sec1);
1133-
to_talitos_ptr_ext_set(ptr, 0, is_sec1);
1133+
to_talitos_ptr_ext_set(ptr, elen, is_sec1);
11341134

11351135
if (sg_count == 1) {
11361136
to_talitos_ptr(ptr, sg_dma_address(src) + offset, is_sec1);
@@ -1140,7 +1140,7 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
11401140
to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, is_sec1);
11411141
return sg_count;
11421142
}
1143-
sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len,
1143+
sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len + elen,
11441144
&edesc->link_tbl[tbl_off]);
11451145
if (sg_count == 1) {
11461146
/* Only one segment now, so no link tbl needed*/
@@ -1154,6 +1154,15 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
11541154
return sg_count;
11551155
}
11561156

1157+
static int talitos_sg_map(struct device *dev, struct scatterlist *src,
1158+
unsigned int len, struct talitos_edesc *edesc,
1159+
struct talitos_ptr *ptr, int sg_count,
1160+
unsigned int offset, int tbl_off)
1161+
{
1162+
return talitos_sg_map_ext(dev, src, len, edesc, ptr, sg_count, offset,
1163+
tbl_off, 0);
1164+
}
1165+
11571166
/*
11581167
* fill in and submit ipsec_esp descriptor
11591168
*/
@@ -1171,7 +1180,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
11711180
unsigned int ivsize = crypto_aead_ivsize(aead);
11721181
int tbl_off = 0;
11731182
int sg_count, ret;
1174-
int sg_link_tbl_len;
1183+
int elen = 0;
11751184
bool sync_needed = false;
11761185
struct talitos_private *priv = dev_get_drvdata(dev);
11771186
bool is_sec1 = has_ftr_sec1(priv);
@@ -1225,20 +1234,12 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
12251234
* extent is bytes of HMAC postpended to ciphertext,
12261235
* typically 12 for ipsec
12271236
*/
1228-
to_talitos_ptr_len(&desc->ptr[4], cryptlen, is_sec1);
1229-
to_talitos_ptr_ext_set(&desc->ptr[4], 0, is_sec1);
1230-
1231-
sg_link_tbl_len = cryptlen;
1232-
1233-
if (desc->hdr & DESC_HDR_TYPE_IPSEC_ESP) {
1234-
to_talitos_ptr_ext_set(&desc->ptr[4], authsize, is_sec1);
1235-
1236-
if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
1237-
sg_link_tbl_len += authsize;
1238-
}
1237+
if ((desc->hdr & DESC_HDR_TYPE_IPSEC_ESP) &&
1238+
(desc->hdr & DESC_HDR_MODE1_MDEU_CICV))
1239+
elen = authsize;
12391240

1240-
ret = talitos_sg_map(dev, areq->src, sg_link_tbl_len, edesc,
1241-
&desc->ptr[4], sg_count, areq->assoclen, tbl_off);
1241+
ret = talitos_sg_map_ext(dev, areq->src, cryptlen, edesc, &desc->ptr[4],
1242+
sg_count, areq->assoclen, tbl_off, elen);
12421243

12431244
if (ret > 1) {
12441245
tbl_off += ret;

0 commit comments

Comments
 (0)