Skip to contentSkip to conversation

virtio-dmabuf: Ensure UUID persistence for hash table insertion

PATCH In review Dorinda Bassey 3 participants 6 messages Dec 4, 2025 – Feb 9

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 virtio-dmabuf: Ensure UUID persistence for hash table insertion

In virtio_add_resource function, the UUID used as a key for g_hash_table_insert was temporary, which could lead to invalid lookups when accessed later. This patch ensures that the UUID remains valid by duplicating it into a newly allocated memory space. The value is then inserted into the hash table with this persistent UUID key to ensure that the key stored in the hash table remains valid as long as the hash table entry exists.

Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

---
v3: removed blank line between trailers

 hw/display/virtio-dmabuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +4 -2
index 3dba4577ca..5e0395be77 100644
@@ -35,11 +35,13 @@ static bool virtio_add_resource(QemuUUID *uuid, VirtioSharedObject *value)
     if (resource_uuids == NULL) {
         resource_uuids = g_hash_table_new_full(qemu_uuid_hash,
                                                uuid_equal_func,
-                                               NULL,
+                                               g_free,
                                                g_free);
     }
     if (g_hash_table_lookup(resource_uuids, uuid) == NULL) {
-        g_hash_table_insert(resource_uuids, uuid, value);
+        g_hash_table_insert(resource_uuids,
+                            g_memdup2(uuid, sizeof(*uuid)),
+                            value);
     } else {
         result = false;
     }
Signature · 1 line
2.51.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 15 lines · Dorinda Bassey

In virtio_add_resource function, the UUID used as a key for g_hash_table_insert was temporary, which could lead to invalid lookups when accessed later. This patch ensures that the UUID remains valid by duplicating it into a newly allocated memory space. The value is then inserted into the hash table with this persistent UUID key to ensure that the key stored in the hash table remains valid as long as the hash table entry exists.

Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")
Quoted 6 lines

---
v3: removed blank line between trailers

 hw/display/virtio-dmabuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
#2 lore raw
In reply to Dorinda Bassey
Quoted 9 lines · Dorinda Bassey

In virtio_add_resource function, the UUID used as a key for g_hash_table_insert was temporary, which could lead to invalid lookups when accessed later. This patch ensures that the UUID remains valid by duplicating it into a newly allocated memory space. The value is then inserted into the hash table with this persistent UUID key to ensure that the key stored in the hash table remains valid as long as the hash table entry exists.

Quoted 5 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

Again, this feels like a qemu-stable material. However, I'm not sure under which circumstances the uuid key can be freed before referencing.

Please let me know if I shouldn't pick this up for qemu stable releases.

Thanks,

/mjt

Quoted 26 lines

---
v3: removed blank line between trailers

  hw/display/virtio-dmabuf.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +4 -2
index 3dba4577ca..5e0395be77 100644
@@ -35,11 +35,13 @@ static bool virtio_add_resource(QemuUUID *uuid, VirtioSharedObject *value)
      if (resource_uuids == NULL) {
          resource_uuids = g_hash_table_new_full(qemu_uuid_hash,
                                                 uuid_equal_func,
-                                               NULL,
+                                               g_free,
                                                 g_free);
      }
      if (g_hash_table_lookup(resource_uuids, uuid) == NULL) {
-        g_hash_table_insert(resource_uuids, uuid, value);
+        g_hash_table_insert(resource_uuids,
+                            g_memdup2(uuid, sizeof(*uuid)),
+                            value);
      } else {
          result = false;
      }
#3 lore raw

Hi,

Again, this feels like a qemu-stable material. However, I'm not

Quoted 5 lines

sure under which circumstances the uuid key can be freed before referencing.

Please let me know if I shouldn't pick this up for qemu stable releases.

I don't think there's a need to pick this up for stable, I found this issue when testing the resource_assign_uuid feature, which is not yet fully implemented in rust-vmm vhost-device-gpu backend that uses it. So safe to say no existing users are hitting this code path in the current stable.

Br,
Dorinda.

Quoted 56 lines · Michael Tokarev
Quoted 9 lines · Dorinda Bassey

In virtio_add_resource function, the UUID used as a key for g_hash_table_insert was temporary, which could lead to invalid lookups when accessed later. This patch ensures that the UUID remains valid by duplicating it into a newly allocated memory space. The value is then inserted into the hash table with this persistent UUID key to ensure that the key stored in the hash table remains valid as long as the hash table entry exists.

Quoted 5 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

Again, this feels like a qemu-stable material. However, I'm not sure under which circumstances the uuid key can be freed before referencing.

Please let me know if I shouldn't pick this up for qemu stable releases.

Thanks,

/mjt

hw/display/virtio-dmabuf.c static bool virtio_add_resource(QemuUUID *uuid,

Quoted 11 lines

---
v3: removed blank line between trailers

  hw/display/virtio-dmabuf.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +0 -0
index 3dba4577ca..5e0395be77 100644
@@ -35,11 +35,13 @@ static bool virtio_add_resource(QemuUUID *uuid,

VirtioSharedObject *value)

Quoted 15 lines
hw/display/virtio-dmabuf.c +4 -2
      if (resource_uuids == NULL) {
          resource_uuids = g_hash_table_new_full(qemu_uuid_hash,
                                                 uuid_equal_func,
-                                               NULL,
+                                               g_free,
                                                 g_free);
      }
      if (g_hash_table_lookup(resource_uuids, uuid) == NULL) {
-        g_hash_table_insert(resource_uuids, uuid, value);
+        g_hash_table_insert(resource_uuids,
+                            g_memdup2(uuid, sizeof(*uuid)),
+                            value);
      } else {
          result = false;
      }
#4 lore raw
Quoted 10 lines · Dorinda Bassey

Hi,

Again, this feels like a qemu-stable material.  However, I'm not sure under which circumstances the uuid key can be freed before referencing.

Please let me know if I shouldn't pick this up for qemu stable releases.

I don't think there's a need to pick this up for stable, I found this issue when testing the resource_assign_uuid feature, which is not yet fully implemented in rust-vmm vhost-device-gpu backend that uses it. So safe to say no existing users are hitting this code path in the current stable.

This makes sense. I'm dropping this one from the stable series.

But I wonder - for example, 10.0.x is currently a long-term stable release. If rust-vmm changes and implements this feature, won't we hit this issue there? But this time, with a painful debugging session because the current context is forgotten already? :)

Thank you

#5 lore raw
Quoted 4 lines

Again, this feels like a qemu-stable material. However, I'm not sure under which circumstances the uuid key can be freed before referencing.

To clarify the circumstances: in a cross-device sharing scenario like vhost-device-gpu to vhost-device-video if the GPU side UUID is not duplicated, the lookup will fail when the Video device later tries to reference that UUID.

Quoted 4 lines

But I wonder - for example, 10.0.x is currently a long-term stable release. If rust-vmm changes and implements this feature, won't we hit this issue there? But this time, with a painful debugging session because the current context is forgotten already? :)

Hmm, you're right, Better to be safe than sorry, given it's a small fix let's keep it in stable then. Thanks for catching that!

Br,
Dorinda.

Quoted 26 lines · Michael Tokarev
Quoted 6 lines · Dorinda Bassey

Hi,

Again, this feels like a qemu-stable material. However, I'm not sure under which circumstances the uuid key can be freed before referencing.

Quoted 8 lines

Please let me know if I shouldn't pick this up for qemu stable releases.

I don't think there's a need to pick this up for stable, I found this issue when testing the resource_assign_uuid feature, which is not yet fully implemented in rust-vmm vhost-device-gpu backend that uses it. So safe to say no existing users are hitting this code path in the current stable.

This makes sense. I'm dropping this one from the stable series.

But I wonder - for example, 10.0.x is currently a long-term stable release. If rust-vmm changes and implements this feature, won't we hit this issue there? But this time, with a painful debugging session because the current context is forgotten already? :)

Thank you