net/i40e: fix integer overflow
When configuring i40e rx queue, the temporary variable to store max packet length is not big enough which leads to integer overflow issue. This patch is to fix the issue by changing the variable type from uint16_t to uint32_t.
size")
Cc: [email protected]
--- drivers/net/i40e/i40e_rxtx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_rxtx.c +2 -1
@@ -2596,7 +2596,8 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)struct i40e_pf *pf =I40E_VSI_TO_PF (rxq->vsi);struct i40e_hw *hw =I40E_VSI_TO_HW (rxq->vsi);struct rte_eth_dev_data *data = pf->dev_data; -uint16_t buf_size, len; +uint16_t buf_size; +uint32_t len; buf_size = (uint16_t )(rte_pktmbuf_data_room_size (rxq->mp) -RTE_PKTMBUF_HEADROOM );
Signature · 1 line
2.7.4
Quoted 7 lines · Xiao Zhang
When configuring i40e rx queue, the temporary variable to store max packet length is not big enough which leads to integer overflow issue. This patch is to fix the issue by changing the variable type from
uint16_ttouint32_t.Fixes c511a96a34d7 ("mbuf: add accessors for data room and privatesize")
It should be
Quoted 12 lines
Signed-off-by Xiao Zhang <[email protected]>--- drivers/net/i40e/i40e_rxtx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/i40e/i40e_rxtx.c +0
-0
drivers/net/i40e/i40e_rxtx.c i40e_rx_queue_config(struct i40e_rx_queue *rxq) · line 2601
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c +2
-1@@ -2596,7 +2596,8 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)struct i40e_pf *pf =I40E_VSI_TO_PF (rxq->vsi);struct i40e_hw *hw =I40E_VSI_TO_HW (rxq->vsi);struct rte_eth_dev_data *data = pf->dev_data; -uint16_t buf_size, len; +uint16_t buf_size; +uint32_t len;
You can just remove the variable, it's only used once.
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +0
-0buf_size = (uint16_t )(rte_pktmbuf_data_room_size (rxq->mp) -RTE_PKTMBUF_HEADROOM );
Hi Kevin,
Will update the patch according to your comments. Thanks.
Xiao
Quoted 45 lines
-----Original Message-----
From: Kevin Traynor [mailto:[email protected]]
Sent: Monday, October 14, 2019 6:36 PM
To: Zhang, Xiao <[email protected]>; [email protected]
Cc: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] net/i40e: fix integer overflowQuoted 7 lines · Xiao Zhang
When configuring i40e rx queue, the temporary variable to store max packet length is not big enough which leads to integer overflow issue. This patch is to fix the issue by changing the variable type from
uint16_ttouint32_t.Fixes c511a96a34d7 ("mbuf: add accessors for data room and privatesize")
It should be
Fixes 4861cde46116 ("i40e: new poll mode driver")Quoted 12 lines
Signed-off-by Xiao Zhang <[email protected]>--- drivers/net/i40e/i40e_rxtx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindex bfe161f..ca15b12 100644drivers/net/i40e/i40e_rxtx.c i40e_rx_queue_config(struct i40e_rx_queue *rxq) · line 2601
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c +2
-1@@ -2596,7 +2596,8 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)struct i40e_pf *pf =I40E_VSI_TO_PF (rxq->vsi);struct i40e_hw *hw =I40E_VSI_TO_HW (rxq->vsi);struct rte_eth_dev_data *data = pf->dev_data; -uint16_t buf_size, len; +uint16_t buf_size; +uint32_t len;You can just remove the variable, it's only used once.
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +0
-0buf_size = (uint16_t )(rte_pktmbuf_data_room_size (rxq->mp) -RTE_PKTMBUF_HEADROOM );
PATCH v2 1/1 net/i40e: fix integer overflow
In reply to Xiao ZhangWhen config i40e rx queue, the temporary variable to store max packet length is not big enough which leads to integer overflow issue. This patch is to fix the issue by removing the variable and using the expression directly since the variable only used once.
---
v2
Correct the fixline and remove temporary variable.
--- drivers/net/i40e/i40e_rxtx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_rxtx.c +4 -3
@@ -2596,7 +2596,7 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)struct i40e_pf *pf =I40E_VSI_TO_PF (rxq->vsi);struct i40e_hw *hw =I40E_VSI_TO_HW (rxq->vsi);struct rte_eth_dev_data *data = pf->dev_data; -uint16_t buf_size, len; +uint16_t buf_size; buf_size = (uint16_t )(rte_pktmbuf_data_room_size (rxq->mp) -RTE_PKTMBUF_HEADROOM );
@@ -2619,8 +2619,9 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)break ; } - len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len; - rxq->max_pkt_len =RTE_MIN (len, data->dev_conf.rxmode.max_rx_pkt_len); + rxq->max_pkt_len = +RTE_MIN ((uint32_t )(hw->func_caps.rx_buf_chain_len * + rxq->rx_buf_len), data->dev_conf.rxmode.max_rx_pkt_len);if (data->dev_conf.rxmode.offloads &DEV_RX_OFFLOAD_JUMBO_FRAME ) {if (rxq->max_pkt_len <=RTE_ETHER_MAX_LEN || rxq->max_pkt_len >I40E_FRAME_SIZE_MAX ) {
Signature · 1 line
2.7.4
Quoted 44 lines · Xiao Zhang
When config i40e rx queue, the temporary variable to store max packet length is not big enough which leads to integer overflow issue. This patch is to fix the issue by removing the variable and using the expression directly since the variable only used once.
Fixes 4861cde46116 ("i40e: new poll mode driver")Signed-off-by Xiao Zhang <[email protected]>---
v2
Correct the fixline and remove temporary variable.
---drivers/net/i40e/i40e_rxtx.c| 7 ++++---1 file changed, 4 insertions(+), 3 deletions(-)drivers/net/i40e/i40e_rxtx.c +4
-3@@ -2596,7 +2596,7 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)struct i40e_pf *pf =I40E_VSI_TO_PF (rxq->vsi);struct i40e_hw *hw =I40E_VSI_TO_HW (rxq->vsi);struct rte_eth_dev_data *data = pf->dev_data; -uint16_t buf_size, len; +uint16_t buf_size; buf_size = (uint16_t )(rte_pktmbuf_data_room_size (rxq->mp) -RTE_PKTMBUF_HEADROOM );@@ -2619,8 +2619,9 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq)break ; } - len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len; - rxq->max_pkt_len =RTE_MIN (len, data->dev_conf.rxmode.max_rx_pkt_len); + rxq->max_pkt_len = +RTE_MIN ((uint32_t )(hw->func_caps.rx_buf_chain_len * + rxq->rx_buf_len), data->dev_conf.rxmode.max_rx_pkt_len);if (data->dev_conf.rxmode.offloads &DEV_RX_OFFLOAD_JUMBO_FRAME ) {if (rxq->max_pkt_len <=RTE_ETHER_MAX_LEN || rxq->max_pkt_len >I40E_FRAME_SIZE_MAX ) {Signature · 1 line
2.7.4
Applied to dpdk-next-net-intel.