From patchwork Sat Apr 22 16:45:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Eremin-Solenikov X-Patchwork-Id: 97952 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp800493qgf; Sat, 22 Apr 2017 09:45:37 -0700 (PDT) X-Received: by 10.55.93.131 with SMTP id r125mr6075968qkb.79.1492879537894; Sat, 22 Apr 2017 09:45:37 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v41si13318620qtc.250.2017.04.22.09.45.37; Sat, 22 Apr 2017 09:45:37 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8042960AC8; Sat, 22 Apr 2017 16:45:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id B6355607DC; Sat, 22 Apr 2017 16:45:32 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BCADC60983; Sat, 22 Apr 2017 16:45:30 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id CFCE560668 for ; Sat, 22 Apr 2017 16:45:29 +0000 (UTC) Received: by mail-lf0-f52.google.com with SMTP id t144so57208689lff.1 for ; Sat, 22 Apr 2017 09:45:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Kuapnjjyw7VOeFEHlIWuByz6XaewXo7D0euMrRQILX8=; b=t5wT6xPY87rllCHYTxclxpB7VONd2qIXYdTMw215Q8n4AU3tbFUJAFQCTGL6qkS2qo Vb5hebx6rRHf4voszylqcYqBmkd5KCKKiVseRV5EIxrYHYXW2a3QYR2MzofMO5aQDgBi QGWgAAuSbwY1cfaIdT2vKyUxX6UBbarZqOcXptvOU4Q1ZXhk9c7UPHMKulI5V1nNOc1O cusKPokjUyv2MdH4uX5LaqhLuclhH/Mb0MgHX0nMVXUOJANTFFR5eSU81yEC3x8hqJNz ErNjC1o2cuvWNP9KhuZsWMIKXY88jjoVP0InfkCPIPmop/CXgeFa1F3zBCk6K7p4u+rh BlSA== X-Gm-Message-State: AN3rC/5pa9APC+PHtK9A3wYJJYeufOXuZmMxbUtir6kAmkIZn9al99gn REmQpZRMza/DfeZ8nQTJN2co X-Received: by 10.25.68.10 with SMTP id r10mr6178688lfa.136.1492879528339; Sat, 22 Apr 2017 09:45:28 -0700 (PDT) Received: from forlindon.lumag.auriga.ru ([94.25.228.40]) by smtp.gmail.com with ESMTPSA id s126sm2254973lja.43.2017.04.22.09.45.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Apr 2017 09:45:27 -0700 (PDT) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Sat, 22 Apr 2017 19:45:25 +0300 Message-Id: <20170422164525.24883-1-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [lng-odp] [PATCH v3] linux-generic: crypto: properly handle errors in packet copy X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add proper handling for errors returned by odp_packet_copy_from_pkt(). Signed-off-by: Dmitry Eremin-Solenikov --- platform/linux-generic/odp_crypto.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 54b222fd..aaf5931d 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -871,6 +871,7 @@ odp_crypto_operation(odp_crypto_op_param_t *param, odp_crypto_alg_err_t rc_auth = ODP_CRYPTO_ALG_ERR_NONE; odp_crypto_generic_session_t *session; odp_crypto_op_result_t local_result; + odp_bool_t allocated = false; session = (odp_crypto_generic_session_t *)(intptr_t)param->session; @@ -885,12 +886,19 @@ odp_crypto_operation(odp_crypto_op_param_t *param, return -1; } + allocated = true; + if (param->pkt != param->out_pkt) { - (void)odp_packet_copy_from_pkt(param->out_pkt, + int ret; + + ret = odp_packet_copy_from_pkt(param->out_pkt, 0, param->pkt, 0, odp_packet_len(param->pkt)); + if (odp_unlikely(ret < 0)) + goto err; + _odp_packet_copy_md_to_packet(param->pkt, param->out_pkt); odp_packet_free(param->pkt); param->pkt = ODP_PACKET_INVALID; @@ -932,7 +940,7 @@ odp_crypto_operation(odp_crypto_op_param_t *param, op_result->result = local_result; if (odp_queue_enq(session->p.compl_queue, completion_event)) { odp_event_free(completion_event); - return -1; + goto err; } /* Indicate to caller operation was async */ @@ -940,13 +948,21 @@ odp_crypto_operation(odp_crypto_op_param_t *param, } else { /* Synchronous, simply return results */ if (!result) - return -1; + goto err; *result = local_result; /* Indicate to caller operation was sync */ *posted = 0; } return 0; + +err: + if (allocated) { + odp_packet_free(param->out_pkt); + param->out_pkt = ODP_PACKET_INVALID; + } + + return -1; } static void ODP_UNUSED openssl_thread_id(CRYPTO_THREADID ODP_UNUSED *id)