Commit 23fb8f79 authored by LEROY Christophe's avatar LEROY Christophe Committed by Greg Kroah-Hartman

crypto: talitos - fix IPsec cipher in length

commit 2b122730 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: <stable@vger.kernel.org> # 4.8+
Fixes: 549bd8bc ("crypto: talitos - Implement AEAD for SEC1 using HMAC_SNOOP_NO_AFEU")
Reported-by: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Tested-by: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
[backported to 4.9.y, 4.14.y]
Signed-off-by: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b8beca48
...@@ -1116,10 +1116,10 @@ static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count, ...@@ -1116,10 +1116,10 @@ static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count,
return count; return count;
} }
int talitos_sg_map(struct device *dev, struct scatterlist *src, static int talitos_sg_map_ext(struct device *dev, struct scatterlist *src,
unsigned int len, struct talitos_edesc *edesc, unsigned int len, struct talitos_edesc *edesc,
struct talitos_ptr *ptr, struct talitos_ptr *ptr, int sg_count,
int sg_count, unsigned int offset, int tbl_off) unsigned int offset, int tbl_off, int elen)
{ {
struct talitos_private *priv = dev_get_drvdata(dev); struct talitos_private *priv = dev_get_drvdata(dev);
bool is_sec1 = has_ftr_sec1(priv); bool is_sec1 = has_ftr_sec1(priv);
...@@ -1130,7 +1130,7 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src, ...@@ -1130,7 +1130,7 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
} }
to_talitos_ptr_len(ptr, len, is_sec1); to_talitos_ptr_len(ptr, len, is_sec1);
to_talitos_ptr_ext_set(ptr, 0, is_sec1); to_talitos_ptr_ext_set(ptr, elen, is_sec1);
if (sg_count == 1) { if (sg_count == 1) {
to_talitos_ptr(ptr, sg_dma_address(src) + offset, is_sec1); 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, ...@@ -1140,7 +1140,7 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, is_sec1); to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, is_sec1);
return sg_count; return sg_count;
} }
sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len, sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len + elen,
&edesc->link_tbl[tbl_off]); &edesc->link_tbl[tbl_off]);
if (sg_count == 1) { if (sg_count == 1) {
/* Only one segment now, so no link tbl needed*/ /* Only one segment now, so no link tbl needed*/
...@@ -1154,6 +1154,15 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src, ...@@ -1154,6 +1154,15 @@ int talitos_sg_map(struct device *dev, struct scatterlist *src,
return sg_count; return sg_count;
} }
static int talitos_sg_map(struct device *dev, struct scatterlist *src,
unsigned int len, struct talitos_edesc *edesc,
struct talitos_ptr *ptr, int sg_count,
unsigned int offset, int tbl_off)
{
return talitos_sg_map_ext(dev, src, len, edesc, ptr, sg_count, offset,
tbl_off, 0);
}
/* /*
* fill in and submit ipsec_esp descriptor * fill in and submit ipsec_esp descriptor
*/ */
...@@ -1171,7 +1180,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, ...@@ -1171,7 +1180,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
int tbl_off = 0; int tbl_off = 0;
int sg_count, ret; int sg_count, ret;
int sg_link_tbl_len; int elen = 0;
bool sync_needed = false; bool sync_needed = false;
struct talitos_private *priv = dev_get_drvdata(dev); struct talitos_private *priv = dev_get_drvdata(dev);
bool is_sec1 = has_ftr_sec1(priv); bool is_sec1 = has_ftr_sec1(priv);
...@@ -1225,20 +1234,12 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, ...@@ -1225,20 +1234,12 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
* extent is bytes of HMAC postpended to ciphertext, * extent is bytes of HMAC postpended to ciphertext,
* typically 12 for ipsec * typically 12 for ipsec
*/ */
to_talitos_ptr_len(&desc->ptr[4], cryptlen, is_sec1); if ((desc->hdr & DESC_HDR_TYPE_IPSEC_ESP) &&
to_talitos_ptr_ext_set(&desc->ptr[4], 0, is_sec1); (desc->hdr & DESC_HDR_MODE1_MDEU_CICV))
elen = authsize;
sg_link_tbl_len = cryptlen;
if (desc->hdr & DESC_HDR_TYPE_IPSEC_ESP) {
to_talitos_ptr_ext_set(&desc->ptr[4], authsize, is_sec1);
if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
sg_link_tbl_len += authsize;
}
ret = talitos_sg_map(dev, areq->src, sg_link_tbl_len, edesc, ret = talitos_sg_map_ext(dev, areq->src, cryptlen, edesc, &desc->ptr[4],
&desc->ptr[4], sg_count, areq->assoclen, tbl_off); sg_count, areq->assoclen, tbl_off, elen);
if (ret > 1) { if (ret > 1) {
tbl_off += ret; tbl_off += ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment