Skip to contentSkip to conversation

hw/virtio/virtio-nsm: Respond with correct length

PATCH In review Alexander Graf 4 participants 5 messages Feb 13, 2025 – Feb 25, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/virtio/virtio-nsm: Respond with correct length

When we return a response packet from NSM, we need to indicate its length according to the content of the response. Prior to this patch, we returned the length of the source buffer, which may confuse guest code that relies on the response size.

Fix it by returning the response payload size instead.

Fixes bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module device")
---
 hw/virtio/virtio-nsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-nsm.c +1 -1
index 098e1aeac6..b22aa74e34 100644
@@ -1596,7 +1596,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
     g_free(req.iov_base);
     g_free(res.iov_base);
     virtqueue_push(vq, out_elem, 0);
-    virtqueue_push(vq, in_elem, in_elem->in_sg->iov_len);
+    virtqueue_push(vq, in_elem, sz);
     virtio_notify(vdev, vq);
     return;
 
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alexander Graf

When we return a response packet from NSM, we need to indicate its length according to the content of the response. Prior to this patch, we returned the length of the source buffer, which may confuse guest code that relies on the response size.

Fix it by returning the response payload size instead.

Quoted 8 lines
Fixes bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module

device")

---
 hw/virtio/virtio-nsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks for fixing!

Regards,
dorjoy

Reviewed-by Tested-by Vikrant Garg on v1 1/1
#2 lore raw
In reply to Alexander Graf
Quoted 19 lines · Alexander Graf

When we return a response packet from NSM, we need to indicate its length according to the content of the response. Prior to this patch, we returned the length of the source buffer, which may confuse guest code that relies on the response size.

Fix it by returning the response payload size instead.

Fixes bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module device")
---
  hw/virtio/virtio-nsm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-nsm.c +0 -0
index 098e1aeac6..b22aa74e34 100644

hw/virtio/virtio-nsm.c static void handle_input(VirtIODevice *vdev, VirtQueue *vq) · line 1602

Quoted 8 lines
hw/virtio/virtio-nsm.c +1 -1
@@ -1596,7 +1596,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
      g_free(req.iov_base);
      g_free(res.iov_base);
      virtqueue_push(vq, out_elem, 0);
-    virtqueue_push(vq, in_elem, in_elem->in_sg->iov_len);
+    virtqueue_push(vq, in_elem, sz);
      virtio_notify(vdev, vq);
      return;
 

and per https://lore.kernel.org/qemu-devel/CAKXOwk2Eba8qnqKQqCN+=2+N=WRPzAwx3LkoccEwR-3xgt32uw@mail.gmail.com/:

#3 lore raw
In reply to Alexander Graf
Quoted 10 lines · Alexander Graf

When we return a response packet from NSM, we need to indicate its length according to the content of the response. Prior to this patch, we returned the length of the source buffer, which may confuse guest code that relies on the response size.

Fix it by returning the response payload size instead.

Fixes bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module device")

This looks like qemu-stable material (9.2.x).
Please let me know if it is not.

Thanks,

/mjt

#4 lore raw
Quoted 1 line · Michael Tokarev

This looks like qemu-stable material (9.2.x).

Ah, it is already Cc'd to qemu-stable@, -- n/m.