From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7A3E24C74 for ; Thu, 28 Feb 2019 20:21:21 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2019 11:21:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,424,1544515200"; d="scan'208";a="322983987" Received: from sivswdev08.ir.intel.com (HELO localhost.localdomain) ([10.237.217.47]) by fmsmga006.fm.intel.com with ESMTP; 28 Feb 2019 11:21:19 -0800 From: Konstantin Ananyev To: dev@dpdk.org Cc: akhil.goyal@nxp.com, olivier.matz@6wind.com, Konstantin Ananyev Date: Thu, 28 Feb 2019 19:21:01 +0000 Message-Id: <1551381661-21078-7-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1551381661-21078-1-git-send-email-konstantin.ananyev@intel.com> References: <1551381661-21078-1-git-send-email-konstantin.ananyev@intel.com> Subject: [dpdk-dev] [PATCH 6/6] ipsec: reorder packet check for esp inbound 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: , X-List-Received-Date: Thu, 28 Feb 2019 19:21:22 -0000 Right now check for packet length and padding is done inside cop_prepare(). It makes sense to have all necessary checks in one place at early stage: inside pkt_prepare(). That allows to simplify (and later hopefully) optimize cop_prepare() part. Signed-off-by: Konstantin Ananyev --- lib/librte_ipsec/esp_inb.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/librte_ipsec/esp_inb.c b/lib/librte_ipsec/esp_inb.c index 562185ebe..d479af8ea 100644 --- a/lib/librte_ipsec/esp_inb.c +++ b/lib/librte_ipsec/esp_inb.c @@ -26,11 +26,6 @@ inb_cop_prepare(struct rte_crypto_op *cop, struct rte_crypto_sym_op *sop; struct aead_gcm_iv *gcm; uint64_t *ivc, *ivp; - uint32_t clen; - - clen = plen - sa->ctp.cipher.length; - if ((int32_t)clen < 0 || (clen & (sa->pad_align - 1)) != 0) - return -EINVAL; /* fill sym op fields */ sop = cop->sym; @@ -38,7 +33,7 @@ inb_cop_prepare(struct rte_crypto_op *cop, /* AEAD (AES_GCM) case */ if (sa->aad_len != 0) { sop->aead.data.offset = pofs + sa->ctp.cipher.offset; - sop->aead.data.length = clen; + sop->aead.data.length = plen - sa->ctp.cipher.length; sop->aead.digest.data = icv->va; sop->aead.digest.phys_addr = icv->pa; sop->aead.aad.data = icv->va + sa->icv_len; @@ -53,7 +48,7 @@ inb_cop_prepare(struct rte_crypto_op *cop, /* CRYPT+AUTH case */ } else { sop->cipher.data.offset = pofs + sa->ctp.cipher.offset; - sop->cipher.data.length = clen; + sop->cipher.data.length = plen - sa->ctp.cipher.length; sop->auth.data.offset = pofs + sa->ctp.auth.offset; sop->auth.data.length = plen - sa->ctp.auth.length; sop->auth.digest.data = icv->va; @@ -101,7 +96,7 @@ inb_pkt_prepare(const struct rte_ipsec_sa *sa, const struct replay_sqn *rsn, { int32_t rc; uint64_t sqn; - uint32_t icv_ofs, plen; + uint32_t clen, icv_ofs, plen; struct rte_mbuf *ml; struct esp_hdr *esph; @@ -128,6 +123,11 @@ inb_pkt_prepare(const struct rte_ipsec_sa *sa, const struct replay_sqn *rsn, ml = rte_pktmbuf_lastseg(mb); icv_ofs = ml->data_len - sa->icv_len + sa->sqh_len; + /* check that packet has a valid length */ + clen = plen - sa->ctp.cipher.length; + if ((int32_t)clen < 0 || (clen & (sa->pad_align - 1)) != 0) + return -EBADMSG; + /* we have to allocate space for AAD somewhere, * right now - just use free trailing space at the last segment. * Would probably be more convenient to reserve space for AAD @@ -170,21 +170,19 @@ esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], rc = inb_pkt_prepare(sa, rsn, mb[i], hl, &icv); if (rc >= 0) { lksd_none_cop_prepare(cop[k], cs, mb[i]); - rc = inb_cop_prepare(cop[k], sa, mb[i], &icv, hl, rc); - } - - k += (rc == 0); - if (rc != 0) { + inb_cop_prepare(cop[k], sa, mb[i], &icv, hl, rc); + k++; + } else dr[i - k] = i; - rte_errno = -rc; - } } rsn_release(sa, rsn); /* copy not prepared mbufs beyond good ones */ - if (k != num && k != 0) + if (k != num && k != 0) { mbuf_bad_move(mb, dr, num, num - k); + rte_errno = EBADMSG; + } return k; } -- 2.17.1