Skip to contentSkip to conversation

ipsec: packet with null encryption can cause a segfault

PATCH Applied Konstantin Ananyev 2 participants 2 messages Jun 25, 2019 – Jun 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipsec: packet with null encryption can cause a segfault

mbuf_get_seg_ofs() doesn't handle the case when requested offset equals to packet length. Though it is a valid situation for algorithms with no ICV data (IPsec with null encryption as an example).

Fixes 12a0423236a9 ("ipsec: support multi-segment packets")
---
 lib/librte_ipsec/misc.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
lib/librte_ipsec/misc.h +12 -6
index b0cafef4e..fe4641bfc 100644
@@ -46,16 +46,22 @@ move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb,
 static inline struct rte_mbuf *
 mbuf_get_seg_ofs(struct rte_mbuf *mb, uint32_t *ofs)
 {
-	uint32_t k, n;
+	uint32_t k, n, plen;
 	struct rte_mbuf *ms;
 
-	ms = mb;
+	plen = mb->pkt_len;
 	n = *ofs;
 
-	for (k = rte_pktmbuf_data_len(ms); n >= k;
-			k = rte_pktmbuf_data_len(ms)) {
-		ms = ms->next;
-		n -= k;
+	if (n == plen) {
+		ms = rte_pktmbuf_lastseg(mb);
+		n = n + rte_pktmbuf_data_len(ms) - plen;
+	} else {
+		ms = mb;
+		for (k = rte_pktmbuf_data_len(ms); n >= k;
+				k = rte_pktmbuf_data_len(ms)) {
+			ms = ms->next;
+			n -= k;
+		}
 	}
 
 	*ofs = n;
Signature · 1 line
2.17.1
Applied
#1 lore raw
Quoted 9 lines

mbuf_get_seg_ofs() doesn't handle the case when requested offset equals to packet length. Though it is a valid situation for algorithms with no ICV data (IPsec with null encryption as an example).

Fixes 12a0423236a9 ("ipsec: support multi-segment packets")

---

Applied.

Squashed with the original commit.

Thanks.