check illegal packets
cover check illegal packets
Check whether the data packet is illegal of ice and iavf driver.
Kevin Liu (2):
net/iavf: check illegal packets
net/ice: check illegal packets
drivers/net/iavf/iavf_rxtx.c | 10 +++++++++- drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/ice/ice_rxtx.c | 13 +++++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
PATCH 1/2 net/iavf: check illegal packets
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.
--- drivers/net/iavf/iavf_rxtx.c | 10 +++++++++- drivers/net/iavf/iavf_rxtx.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf_rxtx.c +9 -1
@@ -2877,7 +2877,8 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,/* Check condition for nb_segs > IAVF_TX_MAX_MTU_SEG. */ if (!(ol_flags &RTE_MBUF_F_TX_TCP_SEG )) { -if (m->nb_segs >IAVF_TX_MAX_MTU_SEG ) { +if (m->nb_segs >IAVF_TX_MAX_MTU_SEG || + m->pkt_len >IAVF_FRAME_SIZE_MAX ) { rte_errno =EINVAL ;return i; }
@@ -2893,6 +2894,13 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,return i; } +/* check the size of packet */ +if (m->pkt_len <IAVF_TX_MIN_PKT_LEN ) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad pkt_len=[%hu]" , m->pkt_len); +return i; + } +#ifdef RTE_ETHDEV_DEBUG_TX ret =rte_validate_tx_offload (m);if (ret !=0 ) {
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -53,6 +53,8 @@#define IAVF_TSO_MAX_SEG UINT8_MAX#define IAVF_TX_MAX_MTU_SEG 8 +#define IAVF_TX_MIN_PKT_LEN 17 +#define IAVF_TX_CKSUM_OFFLOAD_MASK ( \ RTE_MBUF_F_TX_IP_CKSUM | \ RTE_MBUF_F_TX_L4_MASK | \
Signature · 1 line
2.25.1
RE: [PATCH 1/2] net/iavf: check illegal packets
Quoted 12 lines
-----Original Message-----
From: Liu, KevinX <[email protected]>
Sent: Thursday, September 22, 2022 3:04 PM
To: [email protected]
Cc: Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Yang, SteveX <[email protected]>; Xing, Beilei <[email protected]>; Wu, Jingjing <[email protected]>; Liu, KevinX <[email protected]>
Subject: [PATCH 1/2] net/iavf: check illegal packets
Quoted 2 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.
Better to describe precisely what kind of illegal packets you are going to prevent.
Quoted 55 lines
Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")Signed-off-by Kevin Liu <[email protected]>--- drivers/net/iavf/iavf_rxtx.c | 10 +++++++++- drivers/net/iavf/iavf_rxtx.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-)drivers/net/iavf/iavf_rxtx.c index renamed from drivers/net/iavf/iavf_rxtx.c +0
-0
3deabe1d7e..8ddd809f94100644drivers/net/iavf/iavf_rxtx.c +2
-1@@ -2877,7 +2877,8 @@ iavf_prep_pkts(__rte_unused void *tx_queue,struct rte_mbuf **tx_pkts,/* Check condition for nb_segs > IAVF_TX_MAX_MTU_SEG. */ if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) { - if (m->nb_segs > IAVF_TX_MAX_MTU_SEG) { + if (m->nb_segs > IAVF_TX_MAX_MTU_SEG || + m->pkt_len > IAVF_FRAME_SIZE_MAX) { rte_errno = EINVAL;drivers/net/iavf/iavf_rxtx.c +7
-0return i; }@@ -2893,6 +2894,13 @@ iavf_prep_pkts(__rte_unused void *tx_queue,struct rte_mbuf **tx_pkts, return i; } +/* check the size of packet */ +if (m->pkt_len <IAVF_TX_MIN_PKT_LEN ) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad pkt_len=[%hu]", m->pkt_len); +return i; + } +#ifdef RTE_ETHDEV_DEBUG_TX drivers/net/iavf/iavf_rxtx.c +0
-0ret =rte_validate_tx_offload (m);if (ret !=0 ) {drivers/net/iavf/iavf_rxtx.h index renamed from drivers/net/iavf/iavf_rxtx.h +0
-0
1695e43cd5..bb9083c699100644drivers/net/iavf/iavf_rxtx.h +2
-1@@ -53,6 +53,8 @@#define IAVF_TSO_MAX_SEG UINT8_MAX#define IAVF_TX_MAX_MTU_SEG 8 +#define IAVF_TX_MIN_PKT_LEN 17 +#define IAVF_TX_CKSUM_OFFLOAD_MASK ( \ RTE_MBUF_F_TX_IP_CKSUM | \ RTE_MBUF_F_TX_L4_MASK | \ --2.25.1
PATCH 2/2 net/ice: check illegal packets
In reply to Kevin LiuSome 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.
--- drivers/net/ice/ice_rxtx.c | 13 +++++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 2 files changed, 15 insertions(+)
drivers/net/ice/ice_rxtx.c +13 -0
@@ -3458,6 +3458,19 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,return i; } +/* check the size of packet */ +if (!(ol_flags &RTE_MBUF_F_TX_TCP_SEG ) && + m->pkt_len >ICE_FRAME_SIZE_MAX ) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad pkt_len=[%hu]" , m->pkt_len); +return i; + } +if (m->pkt_len <ICE_TX_MIN_PKT_LEN ) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad pkt_len=[%hu]" , m->pkt_len); +return i; + } +#ifdef RTE_ETHDEV_DEBUG_TX ret =rte_validate_tx_offload (m);if (ret !=0 ) {
drivers/net/ice/ice_rxtx.h +2 -0
@@ -40,6 +40,8 @@#define ICE_RXDID_COMMS_OVS 22 +#define ICE_TX_MIN_PKT_LEN 17 +extern uint64_t ice_timestamp_dynflag;extern int ice_timestamp_dynfield_offset;
Signature · 1 line
2.25.1
v2 cover check illegal packets
In reply to Kevin LiuCheck whether the data packet is illegal of ice and iavf driver.
v2:
Change the scheme, check the data_len and update commit log.
Kevin Liu (2):
net/iavf: check illegal packets
net/ice: check illegal packets
drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/ice/ice_rxtx.c | 11 +++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 4 files changed, 24 insertions(+)
Signature · 1 line
2.25.1
PATCH v2 1/2 net/iavf: check illegal packets
If the length of data_len in mbuf is less than 17 or greater than the maximum frame size, it is illegal.
These 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.
--- drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ 2 files changed, 11 insertions(+)
drivers/net/iavf/iavf_rxtx.c +9 -0
@@ -2865,6 +2865,7 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,struct rte_mbuf *m;struct iavf_tx_queue *txq = tx_queue;struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id]; +uint16_t max_frame_size = dev->data->mtu +IAVF_ETH_OVERHEAD ;struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (dev->data->dev_private);struct iavf_adapter *adapter =IAVF_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private);
@@ -2893,6 +2894,14 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,return i; } +/* check the data_len in mbuf */ +if (m->data_len <IAVF_TX_MIN_PKT_LEN || + m->data_len > max_frame_size) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad data_len=[%hu]" , m->data_len); +return i; + } +#ifdef RTE_ETHDEV_DEBUG_TX ret =rte_validate_tx_offload (m);if (ret !=0 ) {
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -53,6 +53,8 @@#define IAVF_TSO_MAX_SEG UINT8_MAX#define IAVF_TX_MAX_MTU_SEG 8 +#define IAVF_TX_MIN_PKT_LEN 17 +#define IAVF_TX_CKSUM_OFFLOAD_MASK ( \ RTE_MBUF_F_TX_IP_CKSUM | \ RTE_MBUF_F_TX_L4_MASK | \
Signature · 1 line
2.25.1
PATCH v2 2/2 net/ice: check illegal packets
In reply to Kevin LiuIf the length of data_len in mbuf is less than 17 or greater than the maximum frame size, it is illegal.
These 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.
--- drivers/net/ice/ice_rxtx.c | 11 +++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/net/ice/ice_rxtx.c +11 -0
@@ -3442,6 +3442,9 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,int i, ret;uint64_t ol_flags;struct rte_mbuf *m; +struct ice_tx_queue *txq = tx_queue; +struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id]; +uint16_t max_frame_size = dev->data->mtu +ICE_ETH_OVERHEAD ;for (i =0 ; i < nb_pkts; i++) { m = tx_pkts[i];
@@ -3458,6 +3461,14 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,return i; } +/* check the data_len in mbuf */ +if (m->data_len <ICE_TX_MIN_PKT_LEN || + m->data_len > max_frame_size) { + rte_errno =EINVAL ; +PMD_DRV_LOG (ERR ,"INVALID mbuf: bad data_len=[%hu]" , m->data_len); +return i; + } +#ifdef RTE_ETHDEV_DEBUG_TX ret =rte_validate_tx_offload (m);if (ret !=0 ) {
drivers/net/ice/ice_rxtx.h +2 -0
@@ -40,6 +40,8 @@#define ICE_RXDID_COMMS_OVS 22 +#define ICE_TX_MIN_PKT_LEN 17 +extern uint64_t ice_timestamp_dynflag;extern int ice_timestamp_dynfield_offset;
Signature · 1 line
2.25.1
Quoted 21 lines
-----Original Message-----
From: Liu, KevinX <[email protected]>
Sent: Tuesday, September 27, 2022 3:15 PM
To: [email protected]
Cc: Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Yang, SteveX <[email protected]>; Xing, Beilei <[email protected]>; Wu, Jingjing <[email protected]>; Liu, KevinX <[email protected]>
Subject: [PATCH v2 0/2] check illegal packetsCheck whether the data packet is illegal of ice and iavf driver.
v2:
Change the scheme, check thedata_lenand update commit log.Kevin Liu (2):
net/iavf: check illegal packets
net/ice: check illegal packets
Quoted 8 lines
drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/ice/ice_rxtx.c | 11 +++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 4 files changed, 24 insertions(+)--
2.25.1
Applied to dpdk-next-net-intel.
Thanks
Qi
Quoted 10 lines · Kevin Liu
Check whether the data packet is illegal of ice and iavf driver.
v2:
Change the scheme, check thedata_lenand update commit log.Kevin Liu (2):
net/iavf: check illegal packets
net/ice: check illegal packets
Quoted 5 lines
drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/ice/ice_rxtx.c | 11 +++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 4 files changed, 24 insertions(+)
This series looks wrong to me.
- What happens if the application requests TSO to the nic?
- Checking data_len of a mbuf means only checking the size of the first segment, so if any limitation applies to the packet size, it should by checking pkt_len.
I will probably send reverts for the two patches.
Signature · 1 line
David Marchand
Quoted 17 lines · David Marchand
Quoted 10 lines · Kevin Liu
Check whether the data packet is illegal of ice and iavf driver.
v2:
Change the scheme, check thedata_lenand update commit log.Kevin Liu (2):
net/iavf: check illegal packets
net/ice: check illegal packetsQuoted 5 lines
drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/ice/ice_rxtx.c | 11 +++++++++++ drivers/net/ice/ice_rxtx.h | 2 ++ 4 files changed, 24 insertions(+)
Quoted 10 lines
This series looks wrong to me.
- What happens if the application requests TSO to the nic?
- Checkingdata_lenof a mbuf means only checking the size of the first segment, so if any limitation applies to the packet size, it should by checkingpkt_len.I will probably send reverts for the two patches.
there is a fix also that needs to be checked:688cb2f2c61e ("net/ice: fix scalar Tx path segment")