diff mbox series

[dpdk-dev,v2] net/i40e: illagel pactket checking

Message ID 20180608035412.91329-1-yanglong.wu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers show
Series [dpdk-dev,v2] net/i40e: illagel pactket checking | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Yanglong Wu June 8, 2018, 3:54 a.m. UTC
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.

Signed-off-by: Yanglong Wu <yanglong.wu@intel.com>
---
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(+)

Comments

Ananyev, Konstantin June 8, 2018, 2:04 p.m. UTC | #1
> -----Original Message-----
> From: Wu, Yanglong
> Sent: Friday, June 8, 2018 4:54 AM
> To: dev@dpdk.org
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; Ananyev, Konstantin <konstantin.ananyev@intel.com>; Wu, Yanglong
> <yanglong.wu@intel.com>
> 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.
> 
> Signed-off-by: Yanglong Wu <yanglong.wu@intel.com>
> ---
> 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(+)
> 
> diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
> index 6032d5541..05cf3956c 100644
> --- a/drivers/net/i40e/i40e_rxtx.c
> +++ b/drivers/net/i40e/i40e_rxtx.c
> @@ -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 (...) {
	...
}

> +
> +		/*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
Wiles, Keith June 8, 2018, 5:24 p.m. UTC | #2
> On Jun 7, 2018, at 8:54 PM, Yanglong Wu <yanglong.wu@intel.com> wrote:
> 
> 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.

> 
> Signed-off-by: Yanglong Wu <yanglong.wu@intel.com>
> ---
> 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(+)
> 
> diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
> index 6032d5541..05cf3956c 100644
> --- a/drivers/net/i40e/i40e_rxtx.c
> +++ b/drivers/net/i40e/i40e_rxtx.c
> @@ -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; }

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.

> +
> #ifdef RTE_LIBRTE_ETHDEV_DEBUG
> 		ret = rte_validate_tx_offload(m);
> 		if (ret != 0) {
> diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
> index ea73a8a1b..3fc619af9 100644
> --- a/drivers/net/i40e/i40e_rxtx.h
> +++ b/drivers/net/i40e/i40e_rxtx.h
> @@ -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
> 

Regards,
Keith
diff mbox series

Patch

diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index 6032d5541..05cf3956c 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -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) {
diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
index ea73a8a1b..3fc619af9 100644
--- a/drivers/net/i40e/i40e_rxtx.h
+++ b/drivers/net/i40e/i40e_rxtx.h
@@ -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); \