[2/2] crypto/dpaa2_sec: improve error handling

Message ID 1522917349-19049-2-git-send-email-hemant.agrawal@nxp.com
State New
Headers show
Series
  • [1/2] crypto/dpaa_sec: improve the error checking
Related show

Commit Message

Hemant Agrawal April 5, 2018, 8:35 a.m.
From: Sunil Kumar Kori <sunil.kori@nxp.com>


Fixed as reported by NXP's internal coverity.
Also part of dpdk coverity.

Coverity issue: 268331
Coverity issue: 268333

Signed-off-by: Sunil Kumar Kori <sunil.kori@nxp.com>

---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

-- 
2.7.4

Comments

Akhil Goyal April 16, 2018, 9:14 a.m. | #1
On 4/5/2018 2:05 PM, Hemant Agrawal wrote:
> From: Sunil Kumar Kori <sunil.kori@nxp.com>

>

> Fixed as reported by NXP's internal coverity.

> Also part of dpdk coverity.

>

> Coverity issue: 268331

> Coverity issue: 268333

>

> Signed-off-by: Sunil Kumar Kori <sunil.kori@nxp.com>

> ---

Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
De Lara Guarch, Pablo April 17, 2018, 2:42 p.m. | #2
> -----Original Message-----

> From: Akhil Goyal [mailto:akhil.goyal@nxp.com]

> Sent: Monday, April 16, 2018 10:15 AM

> To: Hemant Agrawal <hemant.agrawal@nxp.com>; dev@dpdk.org

> Cc: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; dpdk-

> up@NXP1.onmicrosoft.com

> Subject: Re: [PATCH 2/2] crypto/dpaa2_sec: improve error handling

> 

> On 4/5/2018 2:05 PM, Hemant Agrawal wrote:

> > From: Sunil Kumar Kori <sunil.kori@nxp.com>

> >

> > Fixed as reported by NXP's internal coverity.

> > Also part of dpdk coverity.

> >

> > Coverity issue: 268331

> > Coverity issue: 268333

> >

> > Signed-off-by: Sunil Kumar Kori <sunil.kori@nxp.com>

> > ---

> Acked-by: Akhil Goyal <akhil.goyal@nxp.com>


Added Fixes line and CC'd stable.

Applied to dpdk-next-crypto.
Thanks,

Pablo

Patch

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 23012e3..d02d821 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -1627,7 +1627,7 @@  dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo authdata;
-	unsigned int bufsize, i;
+	int bufsize, i;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1723,6 +1723,10 @@  dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
 				   1, 0, &authdata, !session->dir,
 				   session->digest_length);
+	if (bufsize < 0) {
+		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		goto error_out;
+	}
 
 	flc->word1_sdl = (uint8_t)bufsize;
 	flc->word2_rflc_31_0 = lower_32_bits(
@@ -1753,7 +1757,7 @@  dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo aeaddata;
-	unsigned int bufsize, i;
+	int bufsize, i;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 	struct rte_crypto_aead_xform *aead_xform = &xform->aead;
@@ -1844,6 +1848,11 @@  dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 				priv->flc_desc[0].desc, 1, 0,
 				&aeaddata, session->iv.length,
 				session->digest_length);
+	if (bufsize < 0) {
+		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		goto error_out;
+	}
+
 	flc->word1_sdl = (uint8_t)bufsize;
 	flc->word2_rflc_31_0 = lower_32_bits(
 			(size_t)&(((struct dpaa2_sec_qp *)
@@ -1873,7 +1882,7 @@  dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo authdata, cipherdata;
-	unsigned int bufsize, i;
+	int bufsize, i;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 	struct rte_crypto_cipher_xform *cipher_xform;
@@ -2065,6 +2074,10 @@  dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 					      ctxt->auth_only_len,
 					      session->digest_length,
 					      session->dir);
+		if (bufsize < 0) {
+			DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+			goto error_out;
+		}
 	} else {
 		DPAA2_SEC_ERR("Hash before cipher not supported");
 		goto error_out;
@@ -2156,7 +2169,7 @@  dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
 	struct ipsec_encap_pdb encap_pdb;
 	struct ipsec_decap_pdb decap_pdb;
 	struct alginfo authdata, cipherdata;
-	unsigned int bufsize;
+	int bufsize;
 	struct sec_flow_context *flc;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2346,6 +2359,12 @@  dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
 				1, 0, &decap_pdb, &cipherdata, &authdata);
 	} else
 		goto out;
+
+	if (bufsize < 0) {
+		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		goto out;
+	}
+
 	flc->word1_sdl = (uint8_t)bufsize;
 
 	/* Enable the stashing control bit */