Skip to contentSkip to conversation

net/i40e: illagel pactket checking

PATCH Superseded Yanglong Wu 4 participants 14 messages Jun 7, 2018 – Jun 22, 2018 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/i40e: illagel pactket checking

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

---
 drivers/net/i40e/i40e_rxtx.c | 10 ++++++++++
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 12 insertions(+)
drivers/net/i40e/i40e_rxtx.c +10 -0
index 6032d5541..be00b898e 100644
@@ -1458,6 +1458,16 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/*check the size of pkt len*/
+		if (m->pkt_len > ETHER_MAX_LEN || m->pkt_len < I40E_TX_MIN_PKT_LEN){
+			rte_errno = -EINVAL;
+			return i;}
+
+		/*check the number of mbuf segments*/
+		if(m->nb_segs > I40E_TX_MAX_MTU_SEG){
+			rte_errno = -EINVAL;
+			return i;}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#1 lore raw

Hi Yanglong,

Quoted 23 lines

-----Original Message-----
From: Wu, Yanglong
Sent: Thursday, June 7, 2018 10:40 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Ananyev, Konstantin <[email protected]>; Wu, Yanglong <[email protected]>
Subject: [PATCH] net/i40e: illagel pactket checking

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

---
 drivers/net/i40e/i40e_rxtx.c | 10 ++++++++++
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 12 insertions(+)
drivers/net/i40e/i40e_rxtx.c +0 -0
index 6032d5541..be00b898e 100644

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, · line 1462

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +2 -0
@@ -1458,6 +1458,16 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/*check the size of pkt len*/
+		if (m->pkt_len > ETHER_MAX_LEN || m->pkt_len < I40E_TX_MIN_PKT_LEN){

And why pkt_len greater then ETHER_MAX_LEN is not supported? What about jumbo frames?

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, · line 1467

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +5 -0
+			rte_errno = -EINVAL;
+			return i;}
+
+		/*check the number of mbuf segments*/
+		if(m->nb_segs > I40E_TX_MAX_MTU_SEG){

We already checking that in that function:

	/* Check for m->nb_segs to not exceed the limits. */
                if (!(ol_flags & PKT_TX_TCP_SEG)) {
                        if (m->nb_segs > I40E_TX_MAX_SEG ||
                            m->nb_segs > I40E_TX_MAX_MTU_SEG) {
                                rte_errno = -EINVAL;
                                return i;
                        }
                } else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
                                (m->tso_segsz > I40E_MAX_TSO_MSS)) {
                        /* MSS outside the range (256B - 9674B) are considered
                         * malicious
                         */
                        rte_errno = -EINVAL;
                        return i;
                }

Though it seems it is not totally correct, should probably be:

if (!(ol_flags & PKT_TX_TCP_SEG)) {
	if (m->nb_segs > I40E_TX_MAX_SEG) {
		...
}
} else if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
		m->tso_segsz < I40E_MIN_TSO_MSS ||
		m->tso_segsz > I40E_MAX_TSO_MSS) {
	...
}
Quoted 21 lines
drivers/net/i40e/i40e_rxtx.c +3 -0
+			rte_errno = -EINVAL;
+			return i;}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -1
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
--

2.11.0

#2 lore raw

PATCH v2 1/1 net/i40e: illagel pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and error

---
 drivers/net/i40e/i40e_rxtx.c | 11 +++++++++++
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+)
drivers/net/i40e/i40e_rxtx.c +11 -0
index 6032d5541..05cf3956c 100644
@@ -1458,6 +1458,17 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/*check the size of pkt len*/
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i; }
+
+		/*check the number of mbuf segments*/
+		if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			rte_errno = -EINVAL;
+			return i; }
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#3 lore raw
Quoted 28 lines

-----Original Message-----
From: Wu, Yanglong
Sent: Friday, June 8, 2018 4:54 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Ananyev, Konstantin <[email protected]>; Wu, Yanglong <[email protected]>
Subject: [PATCH v2] net/i40e: illagel pactket checking

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and error

---
 drivers/net/i40e/i40e_rxtx.c | 11 +++++++++++
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+)
drivers/net/i40e/i40e_rxtx.c +0 -0
index 6032d5541..05cf3956c 100644

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, · line 1465

Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +5 -0
@@ -1458,6 +1458,17 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/*check the size of pkt len*/
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i; }

Please follow DPDK coding style:

If (...) {
	...
}

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, · line 1470

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +5 -0
+
+		/*check the number of mbuf segments*/
+		if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			rte_errno = -EINVAL;
+			return i; }

I'll just repeat comment from my previous mail:
We already checking that in that function:

	/* Check for m->nb_segs to not exceed the limits. */
                if (!(ol_flags & PKT_TX_TCP_SEG)) {
                        if (m->nb_segs > I40E_TX_MAX_SEG ||
                            m->nb_segs > I40E_TX_MAX_MTU_SEG) {
                                rte_errno = -EINVAL;
                                return i;
                        }
                } else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
                                (m->tso_segsz > I40E_MAX_TSO_MSS)) {
                        /* MSS outside the range (256B - 9674B) are considered
                         * malicious
                         */
                        rte_errno = -EINVAL;
                        return i;
                }

Though it seems it is not totally correct, should probably be:

if (!(ol_flags & PKT_TX_TCP_SEG)) {
	if (m->nb_segs > I40E_TX_MAX_SEG) {
		...
}
} else if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
		m->tso_segsz < I40E_MIN_TSO_MSS ||
		m->tso_segsz > I40E_MAX_TSO_MSS) {
	...
}

Konstantin

#4 lore raw
In reply to Yanglong Wu
Quoted 7 lines · Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

The subject line has a number of spelling mistakes and that is used in the comments, please fix.

Quoted 18 lines

---
v2:
fix coding style issue and error
---
drivers/net/i40e/i40e_rxtx.c | 11 +++++++++++ drivers/net/i40e/i40e_rxtx.h | 2 ++

2 files changed, 13 insertions(+)
drivers/net/i40e/i40e_rxtx.c +0 -0
index 6032d5541..05cf3956c 100644
@@ -1458,6 +1458,17 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, · line 1470

Quoted 10 lines
drivers/net/i40e/i40e_rxtx.c +10 -0
+		/*check the size of pkt len*/
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i; }
+
+		/*check the number of mbuf segments*/
+		if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			rte_errno = -EINVAL;
+			return i; }

Also I am being a bit picky, but the comments should have a space after the /* and before the */, and of course the changes that Konstantin suggested.

Quoted 20 lines
drivers/net/i40e/i40e_rxtx.c +1 -0
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0

Regards,
Keith

#5 lore raw

PATCH v3 1/1 net/i40e: illagel pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..42b08f1f0 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of pkt len */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#6 lore raw
Quoted 10 lines

-----Original Message-----
From: Wu, Yanglong
Sent: Friday, June 15, 2018 2:19 PM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Ananyev, Konstantin <[email protected]>; Wu, Yanglong <[email protected]>
Subject: [PATCH v3] net/i40e: illagel pactket checking

illagel pactket --> illegal packet

Quoted 2 lines

Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging.

pacth -> patch

Quoted 37 lines

---
v2:
fix coding style issue and error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

6032d5541..42b08f1f0 100644

drivers/net/i40e/i40e_rxtx.c +4 -4
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue,
 struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
drivers/net/i40e/i40e_rxtx.c +0 -0
 			 */

drivers/net/i40e/i40e_rxtx.c i40e_prep_pkts(__rte_unused void *tx_queue, · line 1462

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +1 -0
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue,
 struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of pkt len */

Could be "check the size of packet"

Quoted 24 lines
drivers/net/i40e/i40e_rxtx.c +6 -0
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
drivers/net/i40e/i40e_rxtx.c +0 -0
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h index renamed from drivers/net/i40e/i40e_rxtx.h +0 -0

ea73a8a1b..3fc619af9 100644

drivers/net/i40e/i40e_rxtx.h +2 -1
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
--

2.11.0

#7 lore raw

PATCH v3 1/1 net/i40e: illegal pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..42b08f1f0 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of pkt len */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#8 lore raw

PATCH 1/1 net/i40e: illegal pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and spelling error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..42b08f1f0 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of pkt len */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#9 lore raw

PATCH 1/1 net/i40e: illegal pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and spelling error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..e7916f99c 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of packet */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#10 lore raw

PATCH v3 1/1 net/i40e: illegal pactket checking

In reply to Yanglong Wu

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and spelling error
---
v3:
rework as comments

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..e7916f99c 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of packet */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
#11 lore raw

PATCH v4 1/1 net/i40e: illegal packet checking

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and spelling error
---
v3:
rework as comments
---
v4:
fix spelling error

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..e7916f99c 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of packet */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +2 -0
index ea73a8a1b..3fc619af9 100644
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
Signature · 1 line
2.11.0
Acked-by on v4 1/1
#12 lore raw

Re: [PATCH v4] net/i40e: illegal packet checking

Quoted 70 lines

-----Original Message-----
From: Wu, Yanglong
Sent: Wednesday, June 20, 2018 3:13 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Ananyev, Konstantin <[email protected]>; Wu, Yanglong <[email protected]>
Subject: [PATCH v4] net/i40e: illegal packet checking

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

---
v2:
fix coding style issue and spelling error
---
v3:
rework as comments
---
v4:
fix spelling error

---
 drivers/net/i40e/i40e_rxtx.c | 15 +++++++++++----
 drivers/net/i40e/i40e_rxtx.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +11 -4
index 6032d5541..e7916f99c 100644
@@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* Check for m->nb_segs to not exceed the limits. */
 		if (!(ol_flags & PKT_TX_TCP_SEG)) {
-			if (m->nb_segs > I40E_TX_MAX_SEG ||
-			    m->nb_segs > I40E_TX_MAX_MTU_SEG) {
+			if (m->nb_segs > I40E_TX_MAX_MTU_SEG) {
 				rte_errno = -EINVAL;
 				return i;
 			}
-		} else if ((m->tso_segsz < I40E_MIN_TSO_MSS) ||
-				(m->tso_segsz > I40E_MAX_TSO_MSS)) {
+		} else if (m->nb_segs > I40E_TX_MAX_SEG ||
+			   m->tso_segsz < I40E_MIN_TSO_MSS ||
+			   m->tso_segsz > I40E_MAX_TSO_MSS) {
 			/* MSS outside the range (256B - 9674B) are considered
 			 * malicious
 			 */
@@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of packet */
+		if (m->pkt_len > I40E_FRAME_SIZE_MAX ||
+		    m->pkt_len < I40E_TX_MIN_PKT_LEN) {
+			rte_errno = -EINVAL;
+			return i;
+		}
+
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
drivers/net/i40e/i40e_rxtx.h +0 -0
index ea73a8a1b..3fc619af9 100644

drivers/net/i40e/i40e_rxtx.h

Quoted 9 lines
drivers/net/i40e/i40e_rxtx.h +2 -1
@@ -30,6 +30,8 @@
 #define I40E_TX_MAX_SEG     UINT8_MAX
 #define I40E_TX_MAX_MTU_SEG 8
 
+#define I40E_TX_MIN_PKT_LEN 17
+
 #undef container_of
 #define container_of(ptr, type, member) ({ \
 		typeof(((type *)0)->member)(*__mptr) = (ptr); \
--
Quoted 1 line

2.11.0

Applied
#13 lore raw

Re: [PATCH v4] net/i40e: illegal packet checking

In reply to Yanglong Wu
Quoted 10 lines

-----Original Message-----
From: Wu, Yanglong
Sent: Wednesday, June 20, 2018 10:13 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Ananyev, Konstantin <[email protected]>; Wu, Yanglong <[email protected]>
Subject: [PATCH v4] net/i40e: illegal packet checking

Quoted 4 lines

Some illegal packets will lead to TX/RX hang and can't recover automatically. This patch check those illegal packets and protect TX/RX from hanging.

Applied to dpdk-next-net-intel

Thanks!
Qi>