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 C09E6A0350; Mon, 11 May 2020 12:17:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9FB3E1C221; Mon, 11 May 2020 12:17:31 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D68211C21F for ; Mon, 11 May 2020 12:17:30 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200511101730euoutp027583af570296cdd9898388ab5c5fb417~N8e54nGe50490904909euoutp02m for ; Mon, 11 May 2020 10:17:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200511101730euoutp027583af570296cdd9898388ab5c5fb417~N8e54nGe50490904909euoutp02m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1589192250; bh=LC3S520H1X8s4Jll2FNiAGW9P1hE0vNoS2xqwMRNR+o=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=Gz67Ty4g29tL5abahRlAd2mi9yxxzs/pSQM7QTW0YLKxVNYMJ3Vr43hivfWrkrbat xipOE4pD2VkHKtZmb8M+PdnNQKMF6gk8Eba0lxKLWPF6cKnDpCiIzAmI4gF6Pzj1Xl 3ivuf56pFUb2gg8K6NOXqUrNJstLwyHxXweGmCm8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200511101729eucas1p2679d36691c26d3aeef4a683b075f4ac7~N8e5xZ2uv2968529685eucas1p2Z; Mon, 11 May 2020 10:17:29 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 85.B9.60698.93629BE5; Mon, 11 May 2020 11:17:29 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200511101729eucas1p254898c8ef58a873da3a389f7ad73eab8~N8e5aDmTj2037720377eucas1p2u; Mon, 11 May 2020 10:17:29 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200511101729eusmtrp1697d5649880625f240b258abaa9a68e2~N8e5Zgw-q3063730637eusmtrp17; Mon, 11 May 2020 10:17:29 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-d1-5eb9263917f4 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 90.E9.08375.93629BE5; Mon, 11 May 2020 11:17:29 +0100 (BST) Received: from [106.210.88.70] (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200511101729eusmtip1467085146c99312d0129b6bcc1d42827~N8e5AMZTM1306613066eusmtip1e; Mon, 11 May 2020 10:17:29 +0000 (GMT) To: Akhil Goyal , Hemant Agrawal Cc: "dev@dpdk.org" From: Lukasz Wojciechowski Message-ID: <18e9077f-2f8a-0809-5b39-89ebc54b6e9b@partner.samsung.com> Date: Mon, 11 May 2020 12:17:27 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Transfer-Encoding: 8bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkleLIzCtJLcpLzFFi42LZduzneV1LtZ1xBivXmFusPzOP0eLdp+1M Fisfb2RzYPb4tWApq8fGdzuYApiiuGxSUnMyy1KL9O0SuDImr9nEVLBXrKJrgkoD4w+BLkZO DgkBE4l1EzezdDFycQgJrGCU2PRrOpTzhVFi84mljBDOZ0aJQzfOM8G07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GUFsUYFYidXX WhkhagQlTs58AlbDCRS/cf07C8QCM4l5mx8yQ9jyEs1bZ0PZ4hK3nsxnmsAoNAtJ+ywkLbOQ tMxC0rKAkWUVo0hqaXFuem6xoV5xYm5xaV66XnJ+7iZGYKxsO/Zz8w7GSxuDDzEKcDAq8fAG KOyIE2JNLCuuzD3EKMHBrCTC63EPKMSbklhZlVqUH19UmpNafIjRFOi5icxSosn5wDjOK4k3 NDU0t7A0NDc2NzazUBLn7RA4GCMkkJ5YkpqdmlqQWgTTx8TBKdXAaLf8Yd9foxSrt7+KZrmt iHgmVpG+Ze/OTxU8okf6tHfeVvkQY/bYRcvfWorzp9yNCXt/LV3t8aUyqCtjbvpDWe/EtVUy rhdeKz2ZI7XfT2B7Z5rs4b3Jgj/PF75j6mq8dH1K2zT3tDpZ4RvSPasSJLaYJN/RFE6fomU3 8c0ao7I2je/XZvmuUmIpzkg01GIuKk4EAPUsxGerAgAA X-CMS-MailID: 20200511101729eucas1p254898c8ef58a873da3a389f7ad73eab8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200505214128eucas1p26202807ca7da9e16c1628fd63cb2dfeb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200505214128eucas1p26202807ca7da9e16c1628fd63cb2dfeb References: <20200505214105.19465-1-l.wojciechow@partner.samsung.com> Subject: Re: [dpdk-dev] [PATCH 1/2] crypto/dpaa_sec: improve memory freeing 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" W dniu 09.05.2020 o 23:58, Akhil Goyal pisze: > Hi Lukasz, > > Thanks for the detailed analysis. > Series > Acked-by: Akhil Goyal > > Applied to dpdk-next-crypto > > Thanks. I am a fan of big commit messages. Just let me know when I'll cross the line withe these novels ;) Thank you >> This patch fixes management of memory for authentication >> and encryption keys. >> There were two issues with former state of implementation: >> >> 1) Invalid access to dpaa_sec_session union members >> The dpaa_sec_session structure includes an anonymous union: >> union { >> struct {...} aead_key; >> struct { >> struct {...} cipher_key; >> struct {...} auth_key; >> }; >> }; >> Depending on the used algorithm a rte_zmalloc() function >> allocated memory that was kept in aead_key, cipher_key >> or auth_key. However every time the memory was released, >> rte_free() was called only on cipher and auth keys, even >> if pointer to allocated memory was stored in aead_key. >> >> The C language specification defines such behavior as undefined. >> As the cipher_key and aead_key are similar, have same sizes and >> alignment, it has worked, but it's directly against C specification. >> >> This patch fixes this, providing a free_session_data() function >> to free the keys data. It verifies which algorithm was used >> (aead or auth+cipher) and frees proper part of the union. >> >> 2) Some keys might have been freed multiple times >> In functions like: dpaa_sec_cipher_init(), dpaa_sec_auth_init(), >> dpaa_sec_chain_init(), dpaa_sec_aead_init() keys data were freed >> before returning due to some error conditions. However the pointers >> were not zeroed causing another calls to ret_free from higher >> layers of code. This causes an error log about invalid memory address >> to be printed. >> >> This patch fixes it by making only one layer responsible for freeing >> memory: >> * dpaa_sec_set_session_parameters() for allocations made in: >> - dpaa_sec_cipher_init() >> - dpaa_sec_auth_init() >> - dpaa_sec_chain_init() >> - dpaa_sec_aead_init() >> * dpaa_sec_set_ipsec_session() for allocations made in: >> - dpaa_sec_ipsec_aead_init() >> - dpaa_sec_ipsec_proto_init() >> * dpaa_sec_set_pdcp_session() for allocations made in: >> - dpaa_sec_set_pdcp_session() /*only one layer in case of pdcp*/ >> >> Signed-off-by: Lukasz Wojciechowski >> --- -- Lukasz Wojciechowski Principal Software Engineer Samsung R&D Institute Poland Samsung Electronics Office +48 22 377 88 25 l.wojciechow@partner.samsung.com