Skip to contentSkip to conversation

virtio-dmabuf: Ensure UUID persistence for hash table insertion

PATCH In review Dorinda Bassey 4 participants 6 messages Nov 7, 2024 – Dec 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 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")
---
 hw/display/virtio-dmabuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +4 -2
index 3dba4577ca7..5e0395be77c 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.47.0
Reviewed-by on v2 1/1
#1 lore raw
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 6 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

---
hw/display/virtio-dmabuf.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 24 lines
hw/display/virtio-dmabuf.c +4 -2
index 3dba4577ca7..5e0395be77c 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.47.0
#2 lore raw

Hi Albert and Michael,

seems this patch fell through the cracks, It was posted but never picked up. Could you help push it? thanks!

BR,
Dorinda.

Quoted 46 lines · Stefano Garzarella
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 6 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

---
hw/display/virtio-dmabuf.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)

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

Quoted 6 lines
hw/display/virtio-dmabuf.c +0 -0
index 3dba4577ca7..5e0395be77c 100644
@@ -35,11 +35,13 @@ static bool virtio_add_resource(QemuUUID *uuid,

VirtioSharedObject *value)

Quoted 18 lines
hw/display/virtio-dmabuf.c +4 -3
    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;
    }
--

2.47.0

Reviewed-by
#3 lore raw
Quoted 4 lines · Dorinda Bassey

Hi Albert and Michael,

seems this patch fell through the cracks, It was posted but never picked up. Could you help push it? thanks!

I do not remember this patch! Great that you checked, as this fixes a legitimate issue. Hopefully will get integrated this time.

Quoted 24 lines

BR,
Dorinda.

Quoted 19 lines · Stefano Garzarella
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 6 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

---
hw/display/virtio-dmabuf.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
hw/display/virtio-dmabuf.c +4 -3
index 3dba4577ca7..5e0395be77c 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;
    }
--

2.47.0

Reviewed-by on v2 1/1
#4 lore raw
In reply to Dorinda Bassey

Hi

Quoted 10 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 3 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

We missed this patch during the -rc period. Can it be included?

it fixes invalid memory access / use-after-free .

Note: I think the original intent was that the @uuid argument ownership was passed:
virtio_add_dmabuf/virtio_add_vhost_device
* @uuid: new resource's UUID

It could be clarified and be passed as const like getters to eventually help...

Quoted 28 lines
---
 hw/display/virtio-dmabuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +4 -3
index 3dba4577ca7..5e0395be77c 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;
     }
--

2.47.0

Signature · 1 line
Marc-André Lureau
#5 lore raw
Quoted 14 lines · Marc-André Lureau

Hi

Quoted 10 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 7 lines
Quoted 3 lines
Fixes faefdba847 ("hw/display: introduce virtio-dmabuf")

We missed this patch during the -rc period. Can it be included?

I guess we missed this in several releases since it was sent 1 year ago :-)

BTW I think the main issue here was not ccing Michael (now in CC):

$ ./scripts/get_maintainer.pl -f hw/display/virtio-dmabuf.c
Albert Esteve <[email protected]> (supporter:virtio-dmabuf)
"Michael S. Tsirkin" <[email protected]> (supporter:virtio)
[email protected] (open list:All patches CC here)

So, I'm not sure if it's better to rebase and resend (including the R-b) with the right maintainers in CC.

Stefano

Quoted 43 lines

it fixes invalid memory access / use-after-free .

Note: I think the original intent was that the @uuid argument ownership was passed:
virtio_add_dmabuf/virtio_add_vhost_device
* @uuid: new resource's UUID

It could be clarified and be passed as const like getters to eventually help...

Quoted 25 lines
---
 hw/display/virtio-dmabuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/virtio-dmabuf.c +4 -3
index 3dba4577ca7..5e0395be77c 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;
     }
--
Quoted 3 lines

2.47.0

--
Marc-André Lureau