Skip to content

Commit

Permalink
net/iavf: check illegal packet sizes
Browse files Browse the repository at this point in the history
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.

Fixes: a2b29a7 ("net/avf: enable basic Rx Tx")
Cc: [email protected]

Signed-off-by: Kevin Liu <[email protected]>
Acked-by: Qi Zhang <[email protected]>
  • Loading branch information
kevin99012300 authored and qzhan16 committed Sep 30, 2022
1 parent 9b7fcf3 commit 19ee91c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/net/iavf/iavf_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,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);

Expand Down Expand Up @@ -2944,6 +2945,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) {
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/iavf/iavf_rxtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 | \
Expand Down

0 comments on commit 19ee91c

Please sign in to comment.