Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9E36C4332B for ; Fri, 20 Mar 2020 08:06:03 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 2CE7120739 for ; Fri, 20 Mar 2020 08:06:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CE7120739 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7F3C72BBE; Fri, 20 Mar 2020 09:06:02 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id A42602BB9; Fri, 20 Mar 2020 09:06:01 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3814F30E; Fri, 20 Mar 2020 01:06:01 -0700 (PDT) Received: from net-arm-thunderx2-02.shanghai.arm.com (net-arm-thunderx2-02.shanghai.arm.com [10.169.40.171]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7CDD03F305; Fri, 20 Mar 2020 01:10:01 -0700 (PDT) From: Ruifeng Wang To: bernard.iremonger@intel.com, konstantin.ananyev@intel.com Cc: dev@dpdk.org, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, juraj.linkes@pantheon.tech, nd@arm.com, Ruifeng Wang , stable@dpdk.org Date: Fri, 20 Mar 2020 16:05:20 +0800 Message-Id: <20200320080520.144952-1-ruifeng.wang@arm.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v1] test: fix ipsec unit test segfault 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" Segfault was observed when running ipsec unit test: + TestCase [10] : test_ipsec_replay_inb_repeat_null_null_wrapper succeeded + TestCase [11] : test_ipsec_replay_inb_inside_burst_null_null_wrapper succeeded + TestCase [12] : test_ipsec_crypto_inb_burst_2sa_null_null_wrapper succeeded + TestCase [13] : test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper succeeded Segmentation fault Data corruption happens due to incorrect destroy of session. Security session needs process different from crypto session. Destroy corresponding sessions according to different security actions. Fixes: 05fe65eb66b2 ("test/ipsec: introduce functional test") Cc: stable@dpdk.org Signed-off-by: Ruifeng Wang Reviewed-by: Phil Yang Reviewed-by: Gavin Hu --- app/test/test_ipsec.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/test/test_ipsec.c b/app/test/test_ipsec.c index 9e1447293..79d00d7e0 100644 --- a/app/test/test_ipsec.c +++ b/app/test/test_ipsec.c @@ -1167,6 +1167,34 @@ test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i) } } +static void +destroy_dummy_sec_session(struct ipsec_unitest_params *ut, + uint32_t j) +{ + rte_security_session_destroy(&dummy_sec_ctx, + ut->ss[j].security.ses); + ut->ss[j].security.ctx = NULL; +} + +static void +destroy_crypto_session(struct ipsec_unitest_params *ut, + uint8_t crypto_dev, uint32_t j) +{ + rte_cryptodev_sym_session_clear(crypto_dev, ut->ss[j].crypto.ses); + rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses); + memset(&ut->ss[j], 0, sizeof(ut->ss[j])); +} + +static void +destroy_session(struct ipsec_unitest_params *ut, + uint8_t crypto_dev, uint32_t j) +{ + if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE) + return destroy_crypto_session(ut, crypto_dev, j); + else + return destroy_dummy_sec_session(ut, j); +} + static void destroy_sa(uint32_t j) { @@ -1175,9 +1203,8 @@ destroy_sa(uint32_t j) rte_ipsec_sa_fini(ut->ss[j].sa); rte_free(ut->ss[j].sa); - rte_cryptodev_sym_session_clear(ts->valid_dev, ut->ss[j].crypto.ses); - rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses); - memset(&ut->ss[j], 0, sizeof(ut->ss[j])); + + destroy_session(ut, ts->valid_dev, j); } static int -- 2.17.1