From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Trahe, Fiona" Subject: Re: [PATCH v3 3/3] crypto/qat: hebing add null point check and fix mem leak Date: Tue, 23 Jan 2018 12:16:17 +0000 Message-ID: <201801260316.w0Q3GAPv074050@mse01.zte.com.cn> References: <1516675500-10878-1-git-send-email-wang.yong19@zte.com.cn> <1516675500-10878-3-git-send-email-wang.yong19@zte.com.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "dev@dpdk.org" , "Trahe, Fiona" To: Yong Wang , "Xing, Beilei" , "Lu, Wenzhuo" Return-path: Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) by dpdk.org (Postfix) with ESMTP id 3F2901B22A for ; Fri, 26 Jan 2018 04:16:24 +0100 (CET) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 143E74895EB7231E9D3A for ; Fri, 26 Jan 2018 11:16:23 +0800 (CST) Received: from [127.0.0.1] ([10.30.12.226]) by mse01.zte.com.cn with ESMTP id w0Q3GAPv074050 for ; Fri, 26 Jan 2018 11:16:10 +0800 (GMT-8) (envelope-from wang.yong19@zte.com.cn) In-Reply-To: <1516675500-10878-3-git-send-email-wang.yong19@zte.com.cn> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Yong, > -----Original Message----- > From: Yong Wang [mailto:wang.yong19@zte.com.cn] > Sent: Tuesday, January 23, 2018 2:45 AM > To: Xing, Beilei ; Lu, Wenzhuo ; Trahe, Fiona > > Cc: dev@dpdk.org; Yong Wang > Subject: [PATCH v8 3/3] crypto/qat: add null point check and fix mem leak >=20 > 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(). >=20 > Signed-off-by: Yong Wang > --- > 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 | 8 +++++++- > 2 files changed, 17 insertions(+), 1 deletion(-) >=20 > 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_au= th_algo hash_alg, >=20 > in =3D rte_zmalloc("working mem for key", > ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ, 16); > + if (in =3D=3D 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 =3D 0; x < HASH_XCBC_PRECOMP_KEY_NUM; x++) { > @@ -389,6 +394,11 @@ static int qat_alg_do_precomputes(enum icp_qat_hw_au= th_algo hash_alg, > ICP_QAT_HW_GALOIS_E_CTR0_SZ); > in =3D rte_zmalloc("working mem for key", > ICP_QAT_HW_GALOIS_H_SZ, 16); > + if (in =3D=3D 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) !=3D 0) { > diff --git a/drivers/crypto/qat/qat_qp.c b/drivers/crypto/qat/qat_qp.c > index 0941a58..812dce9 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 *de= v, uint16_t > queue_pair_id, > qp->op_cookies =3D rte_zmalloc("qat PMD op cookie pointer", > qp_conf->nb_descriptors * sizeof(*qp->op_cookies), > RTE_CACHE_LINE_SIZE); > + if (qp->op_cookies =3D=3D NULL) { > + PMD_DRV_LOG(ERR, "Failed to alloc mem for cookie"); > + rte_free(qp); > + return -ENOMEM; > + } >=20 > qp->mmap_bar_addr =3D pci_dev->mem_resource[0].addr; > qp->inflights16 =3D 0; > @@ -192,7 +197,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev= , uint16_t queue_pair_id, > for (i =3D 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; > } >=20 > struct qat_crypto_op_cookie *sql_cookie =3D > @@ -217,6 +222,7 @@ int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev= , uint16_t queue_pair_id, > return 0; >=20 > create_err: [Fiona] Thanks for this - it was on my backlog to fix :) Can you add following too, to cover errors that happen after the rte_mempoo= l_create 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