Skip to content

Commit

Permalink
net/virtio: fix crash when configured twice
Browse files Browse the repository at this point in the history
[ upstream commit 52bd03e969e9b38a7357287aece2488c7f92158f ]

When first attempt to configure a device with RX interrupt enabled fails
for some reason (e.g. because "Multiple intr vector not supported"),
second attempt to configure the device with RX interrupt disabled and
feature set unchanged will succeed but will leave virtio queues not
allocated. Accessing the queues will cause a segfault.

First attempt:
  - virtio_dev_configure()
    - virtio_init_device() is called to reinit the device because
      "dev->data->dev_conf.intr_conf.rxq" is "1"
      - virtio_configure_intr() fails and returns an error
      - virtio_free_queues() frees previously allocated virtio queues
    - virtio_init_device() fails and returns an error
  - virtio_dev_configure() fails and returns an error

Second attempt:
  - virtio_dev_configure()
    - This time virtio_init_device() is not called, virtio queues
      are not allocated

With this fix, reinit the device during configuration if virtio queues
are not allocated.

Fixes: 2b38151 ("net/virtio: fix queue memory leak on error")

Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
achernavin22 authored and cpaelzer committed Nov 11, 2022
1 parent 542536e commit 03a6d4d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/net/virtio/virtio_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,13 @@ virtio_dev_configure(struct rte_eth_dev *dev)
return ret;
}

/* if queues are not allocated, reinit the device */
if (hw->vqs == NULL) {
ret = virtio_init_device(dev, hw->req_guest_features);
if (ret < 0)
return ret;
}

if ((rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
DEV_RX_OFFLOAD_TCP_CKSUM)) &&
!vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM)) {
Expand Down

0 comments on commit 03a6d4d

Please sign in to comment.