From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mxct.zte.com.cn (out1.zte.com.cn [202.103.147.172]) by dpdk.org (Postfix) with ESMTP id C5B33A49A for ; Thu, 25 Jan 2018 08:16:45 +0100 (CET) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id CD0A2DA2D84A200EC6F6; Thu, 25 Jan 2018 15:16:43 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w0P7GVxh030410; Thu, 25 Jan 2018 15:16:31 +0800 (GMT-8) (envelope-from wang.yong19@zte.com.cn) Received: from localhost.localdomain.localdomain ([10.43.166.165]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018012515163817-2598286 ; Thu, 25 Jan 2018 15:16:38 +0800 From: Yong Wang To: fiona.trahe@intel.com Cc: dev@dpdk.org, Yong Wang Date: Thu, 25 Jan 2018 01:53:04 -0500 Message-Id: <1516863184-4713-1-git-send-email-wang.yong19@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-01-25 15:16:38, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-01-25 15:16:19, Serialize complete at 2018-01-25 15:16:19 X-MAIL: mse01.zte.com.cn w0P7GVxh030410 Subject: [dpdk-dev] [PATCH v4] crypto/qat: add null point check and fix mem leak 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: , X-List-Received-Date: Thu, 25 Jan 2018 07:16:47 -0000 There are several func calls to rte_zmalloc() which don't do null point check on the return value. And before return, the memory is not freed. Fix it by adding null point check and rte_free(). Fixes: 1703e94ac5ce ("qat: add driver for QuickAssist devices") Fixes: e09231eaa2af ("crypto/qat: add SGL capability") Signed-off-by: Yong Wang --- v4: * Cover errors that happen after the rte_mempool_create. * Add fix information. v3: * Rebase on master and modify again. v2: * Fix code style warning. --- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 10 ++++++++++ drivers/crypto/qat/qat_qp.c | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c index db6c9a3..26f854c 100644 --- a/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +++ b/drivers/crypto/qat/qat_adf/qat_algs_build_desc.c @@ -359,6 +359,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg, in = rte_zmalloc("working mem for key", ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ, 16); + if (in == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc memory"); + return -ENOMEM; + } + rte_memcpy(in, qat_aes_xcbc_key_seed, ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ); for (x = 0; x < HASH_XCBC_PRECOMP_KEY_NUM; x++) { @@ -389,6 +394,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_auth_algo hash_alg, ICP_QAT_HW_GALOIS_E_CTR0_SZ); in = rte_zmalloc("working mem for key", ICP_QAT_HW_GALOIS_H_SZ, 16); + if (in == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc memory"); + return -ENOMEM; + } + memset(in, 0, ICP_QAT_HW_GALOIS_H_SZ); if (AES_set_encrypt_key(auth_key, auth_keylen << 3, &enc_key) != 0) { diff --git a/drivers/crypto/qat/qat_qp.c b/drivers/crypto/qat/qat_qp.c index 0941a58..87b9ce0 100644 --- a/drivers/crypto/qat/qat_qp.c +++ b/drivers/crypto/qat/qat_qp.c @@ -151,6 +151,11 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, qp->op_cookies = rte_zmalloc("qat PMD op cookie pointer", qp_conf->nb_descriptors * sizeof(*qp->op_cookies), RTE_CACHE_LINE_SIZE); + if (qp->op_cookies == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc mem for cookie"); + rte_free(qp); + return -ENOMEM; + } qp->mmap_bar_addr = pci_dev->mem_resource[0].addr; qp->inflights16 = 0; @@ -192,7 +197,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, for (i = 0; i < qp->nb_descriptors; i++) { if (rte_mempool_get(qp->op_cookie_pool, &qp->op_cookies[i])) { PMD_DRV_LOG(ERR, "QAT PMD Cannot get op_cookie"); - return -EFAULT; + goto create_err; } struct qat_crypto_op_cookie *sql_cookie = @@ -217,6 +222,9 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id, return 0; create_err: + if (qp->op_cookie_pool) + rte_mempool_free(qp->op_cookie_pool); + rte_free(qp->op_cookies); rte_free(qp); return -EFAULT; } -- 1.8.3.1