From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 02CD6A034E; Tue, 22 Feb 2022 19:18:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2594641147; Tue, 22 Feb 2022 19:18:47 +0100 (CET) Received: from out203-205-221-190.mail.qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) by mails.dpdk.org (Postfix) with ESMTP id BF35541163 for ; Tue, 22 Feb 2022 19:18:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1645553923; bh=oSWLP6A+isvMaxUxyTpUue7rcQmU093mPiPPGG0+y9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cqkPWGUwzhMupNXPrqonmhgjSY7wMJYxJ/GCzu61JdDLiYNIxpPrMMMln+ppx8Rbx uG79l05wmPXI4Qezcb97XMx/VZ9pQk2ASdt6KMFbFFJIg9eq8AG//rtLXvc8eZiV59 nAG7SXPlIJdM0C1ajkofKsaxVQiZA4EoGYYEQ5uQ= Received: from localhost.localdomain ([111.193.130.237]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 49223207; Wed, 23 Feb 2022 02:18:18 +0800 X-QQ-mid: xmsmtpt1645553918tw2q88q3l Message-ID: X-QQ-XMAILINFO: MPRquJFDOUjC7ho6kXnIbuLtA88IZQd7FcGiVVSOHs9ifNMf/1Sr+x89W7rIMo mH7TaJJkxVV9lwV8YfmlDgNg+aiD26RAFJmHKJFegkc7Q+ItP+3LMRLjolV2lVbx4quNpCa5ewkI r58pQShQy5OVG05sMk19pUbnr5Zfo/XHY4bwmvxw3r3QKkkP5I7Amagy7NTsj60FF1yjvaGvIdlJ 42NCTqUSKTkRTNSpwLczOXHTTlcjivYUy4pMEGtb6YP1UZ/9u6wyxO7GipznhBM1GtverNN/8Dnn 49sIEz2yMhZjbihg/gBkCI2JHF74sIiTq7JkQpQwOKQ91vw7rYxGy4XnsZ419fO6KGus72xRsJBi tPVhedwjcgoKD/qcEt5JFG0Ko2LDRe8NYsp0SQH+lz0Iw2pf0jP8TguDxShqY6U/WFw/x837srK2 LIGz7ZiSlcVGkbw652JtzUZrHHQ84mZbmS7uHyBdo9JS5H7hH81lHHDV03Sz/92lWBPxyV1NqQgs 9G/icfnpsukg29mHVacZsWCenKZ7OUyUqI3q2oO40Soji0dpZiPaXYMyWAu/aETLR1Wq5YLDt2mV ue0SBfo1CHGw0MLRBlQscAZikcTxQdcFyYBtH4vXsHRGe3MuC1Eu8PS3OZBqSOQQE5m2Gbt0eg+m IyymK3Iik8zb9Y450c/Fb7ikJhVkUPsFcesxZDYQ9JnEISb+762w+o/pYuM3lS202GX0WYCtjcQa dqBqRqOhvHRlSPE4JA1jmdiaeMFGFJ93oKr5535aAuAIK2IeyQzjexQSXCv15QzRbAISxa2ULfpE 0H9T8xpfHWmwILOhZhZP/2GpXXCNmzZE4oa6dbDLgMFLri8E8n0b+bdKDrkNK4AwYHbQcUMb0Kta eP7IVYLTBi/xfM9QGtq3Yno03Vd/KCtZr/Lq99fKj3OlCai6CEtDY= From: Weiguo Li To: dev@dpdk.org Cc: adypodoman@gmail.com, xiaoyun.li@intel.com, tianfei.zhang@intel.com, bruce.richardson@intel.com, ivan.malov@oktetlabs.ru, jgrajcia@cisco.com, hkalra@marvell.com, ying.a.wang@intel.com, ting.xu@intel.com, simei.su@intel.com, qiming.yang@intel.com, motih@mellanox.com, shreyansh.jain@nxp.com, skoteshwar@marvell.com, stephen@networkplumber.org, kalesh-anakkur.purayil@broadcom.com, somnath.kotur@broadcom.com, declan.doherty@intel.com, gakhil@marvell.com, nicolas.chautru@intel.com Subject: [PATCH 04/20] crypto/qat: fix a memory leak when set encrypt key fail Date: Wed, 23 Feb 2022 02:18:02 +0800 X-OQ-MSGID: <68cc1842c6763c0b23b72c951ff45ca18a727387.1645551559.git.liwg06@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org We allocated memory for 'in', we don't free it when AES_set_encrypt_key() fails and it will lead to memory leak. We can move set_encrypt_key() ahead of the memory allocation to fix it. Fixes: 1703e94ac5ce ("qat: add driver for QuickAssist devices") Signed-off-by: Weiguo Li --- drivers/crypto/qat/qat_sym_session.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c index 8ca475ca8b..3dc13942cb 100644 --- a/drivers/crypto/qat/qat_sym_session.c +++ b/drivers/crypto/qat/qat_sym_session.c @@ -1400,18 +1400,17 @@ static int qat_sym_do_precomputes(enum icp_qat_hw_auth_algo hash_alg, memset(p_state_buf, 0, ICP_QAT_HW_GALOIS_H_SZ + ICP_QAT_HW_GALOIS_LEN_A_SZ + ICP_QAT_HW_GALOIS_E_CTR0_SZ); + if (AES_set_encrypt_key(auth_key, auth_keylen << 3, + &enc_key) != 0) { + return -EFAULT; + } in = rte_zmalloc("working mem for key", ICP_QAT_HW_GALOIS_H_SZ, 16); if (in == NULL) { QAT_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) { - return -EFAULT; - } AES_encrypt(in, out, &enc_key); *p_state_len = ICP_QAT_HW_GALOIS_H_SZ + ICP_QAT_HW_GALOIS_LEN_A_SZ + -- 2.25.1