net/vmxnet3: handle bad host framing

Message ID 20200512204003.26686-1-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/vmxnet3: handle bad host framing |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Stephen Hemminger May 12, 2020, 8:40 p.m. UTC
  The VMXNet3 protocol has a start-of-packet (SOP) and end-of-packet (EOP)
marker. If there was a bug where mbuf arrived without SOP the code
that chains the mbuf would dereference a null pointer.
Also, record any mbuf's dropped in statistics.

Although did the initial code no longer have access to VMware.
Compile tested only!

Coverity issue: 124563
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Yong Wang May 13, 2020, 10:24 p.m. UTC | #1
-----Original Message-----
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Tuesday, May 12, 2020 at 1:40 PM
To: Yong Wang <yongwang@vmware.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] net/vmxnet3: handle bad host framing

    The VMXNet3 protocol has a start-of-packet (SOP) and end-of-packet (EOP)
    marker. If there was a bug where mbuf arrived without SOP the code
    that chains the mbuf would dereference a null pointer.
    Also, record any mbuf's dropped in statistics.

    Although did the initial code no longer have access to VMware.
    Compile tested only!

    Coverity issue: 124563
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
    ---

<Acked-by> Yong Wang <yongwang@vmware.com>

     drivers/net/vmxnet3/vmxnet3_rxtx.c | 6 +++++-
     1 file changed, 5 insertions(+), 1 deletion(-)

    diff --git a/drivers/net/vmxnet3/vmxnet3_rxtx.c b/drivers/net/vmxnet3/vmxnet3_rxtx.c
    index dd99684bee4d..73e270f30f00 100644
    --- a/drivers/net/vmxnet3/vmxnet3_rxtx.c
    +++ b/drivers/net/vmxnet3/vmxnet3_rxtx.c
    @@ -950,13 +950,17 @@ vmxnet3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)

     			RTE_ASSERT(rxd->btype == VMXNET3_RXD_BTYPE_BODY);

    -			if (rxm->data_len) {
    +			if (likely(start && rxm->data_len > 0)) {
     				start->pkt_len += rxm->data_len;
     				start->nb_segs++;

     				rxq->last_seg->next = rxm;
     				rxq->last_seg = rxm;
     			} else {
    +				PMD_RX_LOG(ERR, "Error received empty or out of order frame.");
    +				rxq->stats.drop_total++;
    +				rxq->stats.drop_err++;
    +
     				rte_pktmbuf_free_seg(rxm);
     			}
     		}
    -- 
    2.20.1
  
Ferruh Yigit May 14, 2020, 4:15 p.m. UTC | #2
On 5/13/2020 11:24 PM, Yong Wang wrote:
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Date: Tuesday, May 12, 2020 at 1:40 PM
> To: Yong Wang <yongwang@vmware.com>
> Cc: "dev@dpdk.org" <dev@dpdk.org>, Stephen Hemminger <stephen@networkplumber.org>
> Subject: [PATCH] net/vmxnet3: handle bad host framing
> 
>     The VMXNet3 protocol has a start-of-packet (SOP) and end-of-packet (EOP)
>     marker. If there was a bug where mbuf arrived without SOP the code
>     that chains the mbuf would dereference a null pointer.
>     Also, record any mbuf's dropped in statistics.
> 
>     Although did the initial code no longer have access to VMware.
>     Compile tested only!
> 
>     Coverity issue: 124563
>     Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>     ---
> 
> <Acked-by> Yong Wang <yongwang@vmware.com>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/drivers/net/vmxnet3/vmxnet3_rxtx.c b/drivers/net/vmxnet3/vmxnet3_rxtx.c
index dd99684bee4d..73e270f30f00 100644
--- a/drivers/net/vmxnet3/vmxnet3_rxtx.c
+++ b/drivers/net/vmxnet3/vmxnet3_rxtx.c
@@ -950,13 +950,17 @@  vmxnet3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 
 			RTE_ASSERT(rxd->btype == VMXNET3_RXD_BTYPE_BODY);
 
-			if (rxm->data_len) {
+			if (likely(start && rxm->data_len > 0)) {
 				start->pkt_len += rxm->data_len;
 				start->nb_segs++;
 
 				rxq->last_seg->next = rxm;
 				rxq->last_seg = rxm;
 			} else {
+				PMD_RX_LOG(ERR, "Error received empty or out of order frame.");
+				rxq->stats.drop_total++;
+				rxq->stats.drop_err++;
+
 				rte_pktmbuf_free_seg(rxm);
 			}
 		}