examples/vhost: check offset with vlan
authorOuyang Changchun <changchun.ouyang@intel.com>
Wed, 5 Nov 2014 07:10:35 +0000 (15:10 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 5 Nov 2014 21:20:32 +0000 (22:20 +0100)
This patch checks the packet length offset value, and checks if the
extra bytes inside buffer cross page boundary.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
examples/vhost/main.c

index 2916313..a93f7a0 100644 (file)
@@ -1110,7 +1110,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
        }
 
        if (vm2vm_mode == VM2VM_HARDWARE) {
-               if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+               if (find_local_dest(dev, m, &offset, &vlan_tag) != 0 ||
+                       offset > rte_pktmbuf_tailroom(m)) {
                        rte_pktmbuf_free(m);
                        return;
                }
@@ -1896,7 +1897,9 @@ virtio_dev_tx_zcp(struct virtio_net *dev)
 
                /* Buffer address translation. */
                buff_addr = gpa_to_vva(dev, desc->addr);
-               phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len, &addr_type);
+               /* Need check extra VLAN_HLEN size for inserting VLAN tag */
+               phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len + VLAN_HLEN,
+                       &addr_type);
 
                if (likely(packet_success < (free_entries - 1)))
                        /* Prefetch descriptor index. */