On 10/21/2015 11:48 AM, Yuanhan Liu wrote:

[...]
>  
>  #define MAX_PKT_BURST 32
>  
> +static inline int __attribute__((always_inline))
> +is_valid_virt_queue_idx(uint32_t virtq_idx, int is_tx, uint32_t max_qp_idx)
> +{
> +     if ((is_tx ^ (virtq_idx & 0x1)) ||
> +         (virtq_idx >= max_qp_idx * VIRTIO_QNUM))
> +             return 0;
> +
> +     return 1;
> +}
> +
>  /**
>   * This function adds buffers to the virtio devices RX virtqueue. Buffers can
>   * be received from the physical port or from another virtio device. A packet
> @@ -68,12 +78,14 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
>       uint8_t success = 0;
>  
>       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);
> -     if (unlikely(queue_id != VIRTIO_RXQ)) {
> -             LOG_DEBUG(VHOST_DATA, "mq isn't supported in this version.\n");
> +     if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
> +             RTE_LOG(ERR, VHOST_DATA,
> +                     "%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
> +                     __func__, dev->device_fh, queue_id);
>               return 0;
>       }
>  
> -     vq = dev->virtqueue[VIRTIO_RXQ];
> +     vq = dev->virtqueue[queue_id];
>       count = (count > MAX_PKT_BURST) ? MAX_PKT_BURST : count;
>  
>       /*
>
Besides the always_inline issue, i think we should remove the queue_id
check here in the "data" path. Caller should guarantee that they pass us
the correct queue idx.
We could add VHOST_DEBUG macro for the sanity check for debug purpose only.

On the other hand, currently we lack of enough check for the guest
because there could be malicious guests. Plan to fix this in next release.

[...]

Reply via email to