All of lore.kernel.org
 help / color / mirror / Atom feed
From: Isaac Boukris <iboukris@gmail.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbox@nvidia.com>
Cc: dev@dpdk.org, David Marchand <david.marchand@redhat.com>,
	Aman Singh <aman.deep.singh@intel.com>,
	Luca Vizzarro <luca.vizzarro@arm.com>,
	Patrick Robb <patrickrobb1997@gmail.com>,
	Isaac Boukris <iboukris@gmail.com>,
	stable@dpdk.org
Subject: [PATCH v4 3/8] net/virtio-user: fix unaligned reads of control commands
Date: Wed, 18 Nov 2026 10:27:47 +0200	[thread overview]
Message-ID: <20261118082752.1043794-4-iboukris@gmail.com> (raw)
In-Reply-To: <20261118082752.1043794-1-iboukris@gmail.com>

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@dpdk.org

Signed-off-by: Isaac Boukris <iboukris@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


  parent reply	other threads:[~2026-11-18  8:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:43 [PATCH 0/1] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-17 12:43 ` [PATCH 1/1] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 14:29   ` David Marchand
2026-11-17 19:51     ` Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 0/5] net/virtio: fix Rx interrupts " Isaac Boukris
2026-11-17 21:59   ` [PATCH v2 1/5] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 21:59   ` [PATCH v2 2/5] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-17 21:59   ` [PATCH v2 3/5] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-17 22:00   ` [PATCH v2 4/5] dts: support virtio PCI ports Isaac Boukris
2026-11-17 22:00   ` [PATCH v2 5/5] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18  0:19 ` [PATCH v3 0/7] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 1/7] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 2/7] net/virtio-user: fix packet loss with unused queue pairs Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 3/7] test/virtio_user: add unit test of " Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 4/7] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 5/7] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 6/7] dts: support virtio PCI ports Isaac Boukris
2026-11-18  0:19   ` [PATCH v3 7/7] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18  8:27 ` [PATCH v4 0/8] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 1/8] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 2/8] net/virtio-user: fix packet loss with unused queue pairs Isaac Boukris
2026-11-18  8:27   ` Isaac Boukris [this message]
2026-11-18  8:27   ` [PATCH v4 4/8] test/virtio_user: add unit test of " Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 5/8] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 6/8] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 7/8] dts: support virtio PCI ports Isaac Boukris
2026-11-18  8:27   ` [PATCH v4 8/8] dts: add Rx interrupt test suite Isaac Boukris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118082752.1043794-4-iboukris@gmail.com \
    --to=iboukris@gmail.com \
    --cc=aman.deep.singh@intel.com \
    --cc=chenbox@nvidia.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=luca.vizzarro@arm.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=patrickrobb1997@gmail.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.