[PATCH v4 3/8] net/virtio-user: fix unaligned reads of control commands

Isaac Boukris iboukris at gmail.com
Wed Nov 18 09:27:47 CET 2026


The data of a control command follows the 2-byte header and the
1-byte status in the driver's buffer, so it starts at an odd address.
The device emulation reads the number of queue pairs from it through
a pointer to uint16_t, and through a pointer to the RSS configuration
structure. Both reads are unaligned. The undefined behaviour
sanitizer reports the first one for any port with more than one
queue pair:

  virtio_user_dev.c:1001:10: runtime error: load of misaligned
  address 0x7b4802f53f43 for type 'uint16_t', which requires 2 byte
  alignment

Read the number of queue pairs through an unaligned type, and copy
the RSS configuration before reading it.

Fixes: f9b9d1a55775 ("net/virtio-user: add multiple queues in device emulation")
Fixes: dbce501ed7c4 ("net/virtio-user: support RSS")
Cc: stable at dpdk.org

Signed-off-by: Isaac Boukris <iboukris at gmail.com>
---
v4: new patch.

 .../net/virtio/virtio_user/virtio_user_dev.c  | 26 +++++++++----------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index c38ac059df..8617c558ea 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -995,16 +995,15 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri
 	hdr = virtio_user_iova2virt(dev, vring->desc[idx_hdr].addr);
 	if (hdr->class == VIRTIO_NET_CTRL_MQ &&
 	    hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
-		uint16_t queues, *addr;
+		unaligned_uint16_t *queues;
 
-		addr = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
-		queues = *addr;
-		status = virtio_user_handle_mq(dev, queues);
+		queues = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
+		status = virtio_user_handle_mq(dev, *queues);
 	} else if (hdr->class == VIRTIO_NET_CTRL_MQ && hdr->cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) {
-		struct virtio_net_ctrl_rss *rss;
+		struct virtio_net_ctrl_rss rss;
 
-		rss = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
-		status = virtio_user_handle_mq(dev, rss->max_tx_vq);
+		memcpy(&rss, virtio_user_iova2virt(dev, vring->desc[idx_data].addr), sizeof(rss));
+		status = virtio_user_handle_mq(dev, rss.max_tx_vq);
 	} else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
 		   hdr->class == VIRTIO_NET_CTRL_MAC ||
 		   hdr->class == VIRTIO_NET_CTRL_VLAN) {
@@ -1061,16 +1060,15 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
 	hdr = virtio_user_iova2virt(dev, vring->desc[idx_hdr].addr);
 	if (hdr->class == VIRTIO_NET_CTRL_MQ &&
 	    hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
-		uint16_t queues, *addr;
+		unaligned_uint16_t *queues;
 
-		addr = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
-		queues = *addr;
-		status = virtio_user_handle_mq(dev, queues);
+		queues = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
+		status = virtio_user_handle_mq(dev, *queues);
 	} else if (hdr->class == VIRTIO_NET_CTRL_MQ && hdr->cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) {
-		struct virtio_net_ctrl_rss *rss;
+		struct virtio_net_ctrl_rss rss;
 
-		rss = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
-		status = virtio_user_handle_mq(dev, rss->max_tx_vq);
+		memcpy(&rss, virtio_user_iova2virt(dev, vring->desc[idx_data].addr), sizeof(rss));
+		status = virtio_user_handle_mq(dev, rss.max_tx_vq);
 	} else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
 		   hdr->class == VIRTIO_NET_CTRL_MAC ||
 		   hdr->class == VIRTIO_NET_CTRL_VLAN) {
-- 
2.56.1



More information about the dev mailing list