[PATCH v3] hw/net: at least one TX queue and RX queue

Andrew Nguyen posted 1 patch 1 day, 21 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261125-4729-out-of-bounds-rx-interrupt-idx-v3-1-18d377f43be0@gmail.com
Maintainers: Dmitry Fleytman <dmitry.fleytman@gmail.com>, Jason Wang <jasowangio@gmail.com>
hw/net/vmxnet3.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH v3] hw/net: at least one TX queue and RX queue
Posted by Andrew Nguyen 1 day, 21 hours ago
Require a VMXNET3 configuration to have at least one TX queue and one RX
queue.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4729
Reported-by: Karl Mehltretter <kmehltretter@gmail.com>

Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
---
This is a resolution for issue #4729: 
https://gitlab.com/qemu-project/qemu/-/work_items/4729. The issue is that
a VMXNET3 configuration with 0 RX queues is loaded. When one of these RX
queues is accessed anyway, say, rxq_descr[0], it could have an invalid 
interrupt index that was never validated in the first place.
---
Changes in v3:
- Deleted the v1 commit

Cahnges in v2:
- vmxnet3.c: undid v1
- vmxnet3.c: when validating the queues, not interrupt indexes, check for minimum of one

Changes in v1:
- vmxnet3.c: changed the RX queue interrupt index validation for loop to a do-while loop
---
 hw/net/vmxnet3.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 24c551a054..875c998d63 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -1382,17 +1382,18 @@ static bool vmxnet3_validate_queues(VMXNET3State *s)
 {
     /*
     * txq_num and rxq_num are total number of queues
-    * configured by guest. These numbers must not
-    * exceed corresponding maximal values.
+    * configured by guest. These numbers must be at
+    * least one and not exceed corresponding maximal
+    * values.
     */
 
-    if (s->txq_num > VMXNET3_DEVICE_MAX_TX_QUEUES) {
+    if (s->txq_num <= 0 || s->txq_num > VMXNET3_DEVICE_MAX_TX_QUEUES) {
         qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Bad TX queues number: %d\n",
                       s->txq_num);
         return false;
     }
 
-    if (s->rxq_num > VMXNET3_DEVICE_MAX_RX_QUEUES) {
+    if (s->rxq_num <= 0 || s->rxq_num > VMXNET3_DEVICE_MAX_RX_QUEUES) {
         qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Bad RX queues number: %d\n",
                       s->rxq_num);
         return false;

---
base-commit: 6bf90d4fc5027567cb704d7888f5ec792b4ed75a
change-id: 20261115-4729-out-of-bounds-rx-interrupt-idx-78d69a7d847d

Best regards,
-- 
Andrew Nguyen <xmphyr@gmail.com>
Re: [PATCH v3] hw/net: at least one TX queue and RX queue
Posted by Peter Maydell 15 hours ago
On Thu, 26 Nov 2026 at 04:03, Andrew Nguyen <xmphyr@gmail.com> wrote:
>
> Require a VMXNET3 configuration to have at least one TX queue and one RX
> queue.

The commit message should have more in it than this, which only
states what the change does.

A good commit message should explain the "why" of the change
(e.g. what problem the old code is causing and why the
new code is the correct thing to do). In this case for instance
we could mention that although there's no specification for this
device that defines what happens here, having zero queues doesn't
make sense, guest software never tries to configure the device
that way, and other parts of the code implicitly assume that there's
a non-zero number of queues, and we could say what the specific
case reported in the bug is.

> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4729
> Reported-by: Karl Mehltretter <kmehltretter@gmail.com>
>
> Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>

The code changes look good to me.

thanks
-- PMM