Skip to contentSkip to conversation

virtio: fix buffer leak on vlan insert

PATCH Superseded Stephen Hemminger 3 participants 6 messages Apr 5, 2019 – Apr 17, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: fix buffer leak on vlan insert

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")
---
 drivers/net/virtio/virtio_rxtx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/virtio/virtio_rxtx.c +2 -0
index e6f3706d6fe1..2ae4232c181d 100644
@@ -2003,6 +2003,8 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 				rte_pktmbuf_free(txm);
 				continue;
 			}
+			/* vlan_insert may add a header mbuf */
+			tx_pkts[nb_tx] = txm;
 		}
 
 		/* optimize ring usage */
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Stephen Hemminger

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")

---
drivers/net/virtio/virtio_rxtx.c | 2 ++

1 file changed, 2 insertions(+)
drivers/net/virtio/virtio_rxtx.c +0 -0
index e6f3706d6fe1..2ae4232c181d 100644

drivers/net/virtio/virtio_rxtx.c virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts, · line 2010

Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -2003,6 +2003,8 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 				rte_pktmbuf_free(txm);
 				continue;
 			}
+			/* vlan_insert may add a header mbuf */
+			tx_pkts[nb_tx] = txm;
 		}
 
 		/* optimize ring usage */

Good catch. I think we have the same bug in virtio_xmit_pkts() and virtio_xmit_pkts_inorder() and should fix these as well.

Thanks!

regards,
Jens

#2 lore raw

PATCH v2 1/1 virtio: fix buffer leak on vlan insert

In reply to Stephen Hemminger

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")

---
v2 - catch a couple more places.
The virtio code needs some refactoring to not have 3 copies of same loop...

 drivers/net/virtio/virtio_rxtx.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/virtio/virtio_rxtx.c +6 -0
index e6f3706d6fe1..8c56f238f965 100644
@@ -2003,6 +2003,8 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 				rte_pktmbuf_free(txm);
 				continue;
 			}
+			/* vlan_insert may add a header mbuf */
+			tx_pkts[nb_tx] = txm;
 		}
 
 		/* optimize ring usage */
@@ -2090,6 +2092,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 				rte_pktmbuf_free(txm);
 				continue;
 			}
+			/* vlan_insert may add a header mbuf */
+			tx_pkts[nb_tx] = txm;
 		}
 
 		/* optimize ring usage */
@@ -2193,6 +2197,8 @@ virtio_xmit_pkts_inorder(void *tx_queue,
 				rte_pktmbuf_free(txm);
 				continue;
 			}
+			/* vlan_insert may add a header mbuf */
+			tx_pkts[nb_tx] = txm;
 		}
 
 		/* optimize ring usage */
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 7 lines · Stephen Hemminger

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")
Quoted 8 lines

---
v2 - catch a couple more places.
The virtio code needs some refactoring to not have 3 copies of same loop...

drivers/net/virtio/virtio_rxtx.c | 6 ++++++

1 file changed, 6 insertions(+)

Added stable@ back to Cc list as it was for v1.

Reviewed-by on v2 1/1
#4 lore raw
In reply to Stephen Hemminger
Quoted 7 lines · Stephen Hemminger

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")
Quoted 8 lines

---
v2 - catch a couple more places.
The virtio code needs some refactoring to not have 3 copies of same loop...

  drivers/net/virtio/virtio_rxtx.c | 6 ++++++
  1 file changed, 6 insertions(+)

Thanks,
Maxime

#5 lore raw
In reply to Stephen Hemminger
Quoted 7 lines · Stephen Hemminger

The function rte_vlan_insert may allocate a new buffer for the vlan header and return a different mbuf than originally passed. In this case, the stored mbuf in txm[] array could point to wrong buffer.

Fixes dd856dfcb9e7 ("virtio: use any layout on Tx")
Quoted 8 lines

---
v2 - catch a couple more places.
The virtio code needs some refactoring to not have 3 copies of same loop...

  drivers/net/virtio/virtio_rxtx.c | 6 ++++++
  1 file changed, 6 insertions(+)

Applied to dpdk-next-virtio/master.

Note that I fixed the commit title so that it passes check-git-log script.

Thanks,
Maxime