From: Sunil Kumar Kori <sunil.k...@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.k...@nxp.com>
---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

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 */
-- 
2.7.4

Reply via email to