Skip to contentSkip to conversation

mbuf: check sanity of data_len and pkt_len as well

PATCH In review Ilya Matveychikov 3 participants 6 messages Nov 16, 2017 – Jan 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mbuf: check sanity of data_len and pkt_len as well

---
 lib/librte_mbuf/rte_mbuf.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +15 -8
index 7543662f7..491685c36 100644
@@ -202,8 +202,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n,
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 {
-	const struct rte_mbuf *m_seg;
-	unsigned int nb_segs;
+	unsigned int nb_segs, pkt_len;
 
 	if (m == NULL)
 		rte_panic("mbuf is NULL\n");
@@ -220,18 +219,26 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 	if ((cnt == 0) || (cnt == UINT16_MAX))
 		rte_panic("bad ref cnt\n");
 
+	/* data_len supposed to be not more than pkt_len */
+	if (m->data_len > m->pkt_len)
+		rte_panic("bad data_len\n");
+
 	/* nothing to check for sub-segments */
 	if (is_header == 0)
 		return;
 
 	nb_segs = m->nb_segs;
-	m_seg = m;
-	while (m_seg && nb_segs != 0) {
-		m_seg = m_seg->next;
-		nb_segs--;
-	}
-	if (nb_segs != 0)
+	pkt_len = m->pkt_len;
+
+	do {
+		nb_segs -= 1;
+		pkt_len -= m->data_len;
+	} while ((m = m->next) != NULL);
+
+	if (nb_segs)
 		rte_panic("bad nb_segs\n");
+	if (pkt_len)
+		rte_panic("bad pkt_len\n");
 }
 
 /* dump a mbuf on console */

--
2.15.0

#1 lore raw

Hi Ilya,

Quoted 1 line · Ilya Matveychikov

Please, add a commit log.

Quoted 19 lines
---
 lib/librte_mbuf/rte_mbuf.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +1 -2
index 7543662f7..491685c36 100644
@@ -202,8 +202,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n,
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 {
-	const struct rte_mbuf *m_seg;
-	unsigned int nb_segs;
+	unsigned int nb_segs, pkt_len;
 
 	if (m == NULL)
 		rte_panic("mbuf is NULL\n");

lib/librte_mbuf/rte_mbuf.c rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header) · line 225

Quoted 7 lines
lib/librte_mbuf/rte_mbuf.c +4 -0
@@ -220,18 +219,26 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 	if ((cnt == 0) || (cnt == UINT16_MAX))
 		rte_panic("bad ref cnt\n");
 
+	/* data_len supposed to be not more than pkt_len */
+	if (m->data_len > m->pkt_len)
+		rte_panic("bad data_len\n");
+

This check should only be done if is_header == 1.

#2 lore raw

PATCH v2 1/1 mbuf: check sanity of data_len and pkt_len as well

In reply to Ilya Matveychikov

Update rte_mbuf_sanity_check() to check sanity of data_len and pkt_len fields. For segmented packets it is supposed that head's pkt_len field should be the sum of all segments data_len values.

---
 lib/librte_mbuf/rte_mbuf.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +15 -8
index 7543662f7..937fd70ea 100644
@@ -202,8 +202,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n,
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 {
-	const struct rte_mbuf *m_seg;
-	unsigned int nb_segs;
+	unsigned int nb_segs, pkt_len;
 
 	if (m == NULL)
 		rte_panic("mbuf is NULL\n");
@@ -224,14 +223,22 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 	if (is_header == 0)
 		return;
 
+	/* data_len is supposed to be not more than pkt_len */
+	if (m->data_len > m->pkt_len)
+		rte_panic("bad data_len\n");
+
 	nb_segs = m->nb_segs;
-	m_seg = m;
-	while (m_seg && nb_segs != 0) {
-		m_seg = m_seg->next;
-		nb_segs--;
-	}
-	if (nb_segs != 0)
+	pkt_len = m->pkt_len;
+
+	do {
+		nb_segs -= 1;
+		pkt_len -= m->data_len;
+	} while ((m = m->next) != NULL);
+
+	if (nb_segs)
 		rte_panic("bad nb_segs\n");
+	if (pkt_len)
+		rte_panic("bad pkt_len\n");
 }
 
 /* dump a mbuf on console */
Signature · 1 line
2.14.2
#4 lore raw
Quoted 10 lines · Olivier MATZ
Quoted 5 lines · Ilya V. Matveychikov

Update rte_mbuf_sanity_check() to check sanity of data_len and pkt_len fields. For segmented packets it is supposed that head's pkt_len field should be the sum of all segments data_len values.

Thanks

Just realized the title does not match ./devtools/check-git-log.sh constraints. I suggest instead:

mbuf: check sanity of data and packet lengths

#5 lore raw

14/12/2017 10:31, Olivier MATZ:

Quoted 8 lines · Olivier MATZ
Quoted 7 lines · Ilya V. Matveychikov
Quoted 5 lines

Update rte_mbuf_sanity_check() to check sanity of data_len and pkt_len fields. For segmented packets it is supposed that head's pkt_len field should be the sum of all segments data_len values.

Quoted 8 lines
Quoted 3 lines

Thanks

Just realized the title does not match ./devtools/check-git-log.sh constraints. I suggest instead:

mbuf: check sanity of data and packet lengths

Applied, thanks