From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 295BEA0487 for ; Fri, 5 Jul 2019 15:23:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28E641BEB3; Fri, 5 Jul 2019 15:23:57 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 934251BEB2 for ; Fri, 5 Jul 2019 15:23:55 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2019 06:23:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,455,1557212400"; d="scan'208";a="167053571" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.136]) by orsmga003.jf.intel.com with ESMTP; 05 Jul 2019 06:23:53 -0700 From: Fan Zhang To: dev@dpdk.org Cc: akhil.goyal@nxp.com, Fan Zhang Date: Fri, 5 Jul 2019 14:23:49 +0100 Message-Id: <20190705132349.7245-1-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.14.5 Subject: [dpdk-dev] [PATCH] crypto/mvsam: fix missed code change for mvsam X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch fixes the missed "uint8_t *" to "const uint8_t *" xform key data type change for mvsam driver. Fixes: f3390532cf6a ("cryptodev: make xform key pointer constant") Signed-off-by: Fan Zhang --- drivers/crypto/mvsam/rte_mrvl_pmd.c | 44 ++++++++++++++++++++++++++++++--- drivers/crypto/mvsam/rte_mrvl_pmd_ops.c | 9 +++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/mvsam/rte_mrvl_pmd.c b/drivers/crypto/mvsam/rte_mrvl_pmd.c index c2ae82a26..65e4769f2 100644 --- a/drivers/crypto/mvsam/rte_mrvl_pmd.c +++ b/drivers/crypto/mvsam/rte_mrvl_pmd.c @@ -222,6 +222,8 @@ static int mrvl_crypto_set_cipher_session_parameters(struct mrvl_crypto_session *sess, const struct rte_crypto_sym_xform *cipher_xform) { + uint8_t *cipher_key; + /* Make sure we've got proper struct */ if (cipher_xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) { MRVL_LOG(ERR, "Wrong xform struct provided!"); @@ -256,8 +258,17 @@ mrvl_crypto_set_cipher_session_parameters(struct mrvl_crypto_session *sess, return -EINVAL; } + cipher_key = malloc(cipher_xform->cipher.key.length); + if (cipher_key == NULL) { + MRVL_LOG(ERR, "Insufficient memory!"); + return -ENOMEM; + } + + memcpy(cipher_key, cipher_xform->cipher.key, + cipher_xform->cipher.key.length); + sess->sam_sess_params.cipher_key_len = cipher_xform->cipher.key.length; - sess->sam_sess_params.cipher_key = cipher_xform->cipher.key.data; + sess->sam_sess_params.cipher_key = cipher_key; return 0; } @@ -273,6 +284,8 @@ static int mrvl_crypto_set_auth_session_parameters(struct mrvl_crypto_session *sess, const struct rte_crypto_sym_xform *auth_xform) { + uint8_t *auth_key = NULL; + /* Make sure we've got proper struct */ if (auth_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) { MRVL_LOG(ERR, "Wrong xform struct provided!"); @@ -293,9 +306,21 @@ mrvl_crypto_set_auth_session_parameters(struct mrvl_crypto_session *sess, auth_map[auth_xform->auth.algo].auth_alg; sess->sam_sess_params.u.basic.auth_icv_len = auth_xform->auth.digest_length; + + if (auth_xform->auth.key.length > 0) { + auth_key = malloc(auth_xform->auth.key.length); + if (auth_key == NULL) { + MRVL_LOG(ERR, "Not enough memory!"); + return -EINVAL; + } + + memcpy(auth_key, auth_xform->auth.key.data, + auth_xform->auth.key.length); + } + + /* auth_key must be NULL if auth algorithm does not use HMAC */ - sess->sam_sess_params.auth_key = auth_xform->auth.key.length ? - auth_xform->auth.key.data : NULL; + sess->sam_sess_params.auth_key = auth_key; sess->sam_sess_params.auth_key_len = auth_xform->auth.key.length; return 0; @@ -312,6 +337,8 @@ static int mrvl_crypto_set_aead_session_parameters(struct mrvl_crypto_session *sess, const struct rte_crypto_sym_xform *aead_xform) { + uint8_t *aead_key; + /* Make sure we've got proper struct */ if (aead_xform->type != RTE_CRYPTO_SYM_XFORM_AEAD) { MRVL_LOG(ERR, "Wrong xform struct provided!"); @@ -344,7 +371,16 @@ mrvl_crypto_set_aead_session_parameters(struct mrvl_crypto_session *sess, return -EINVAL; } - sess->sam_sess_params.cipher_key = aead_xform->aead.key.data; + aead_key = malloc(aead_xform->aead.key.length); + if (aead_key == NULL) { + MRVL_LOG(ERR, "Insufficient memory!"); + return -ENOMEM; + } + + memcpy(aead_key, aead_xform->aead.key.data, + aead_xform->aead.key.length); + + sess->sam_sess_params.cipher_key = aead_key; sess->sam_sess_params.cipher_key_len = aead_xform->aead.key.length; if (sess->sam_sess_params.cipher_mode == SAM_CIPHER_GCM) diff --git a/drivers/crypto/mvsam/rte_mrvl_pmd_ops.c b/drivers/crypto/mvsam/rte_mrvl_pmd_ops.c index f6bf2cd4c..b334c7694 100644 --- a/drivers/crypto/mvsam/rte_mrvl_pmd_ops.c +++ b/drivers/crypto/mvsam/rte_mrvl_pmd_ops.c @@ -751,6 +751,8 @@ mrvl_crypto_pmd_sym_session_configure(__rte_unused struct rte_cryptodev *dev, return -ENOMEM; } + memset(sess_private_data, 0, sizeof(struct mrvl_crypto_session)); + ret = mrvl_crypto_set_session_parameters(sess_private_data, xform); if (ret != 0) { MRVL_LOG(ERR, "Failed to configure session parameters!"); @@ -769,6 +771,13 @@ mrvl_crypto_pmd_sym_session_configure(__rte_unused struct rte_cryptodev *dev, return -EIO; } + /* free the keys memory allocated for session creation */ + if (mrvl_sess->sam_sess_params.cipher_key != NULL) + free(mrvl_sess->sam_sess_params.cipher_key); + if (mrvl_sess->sam_sess_params.auth_key != NULL) + free(mrvl_sess->sam_sess_params.auth_key); + + return 0; } -- 2.14.5