Skip to contentSkip to conversation

vhost-user-gpu: reorder free calls.

PATCH In review Gerd Hoffmann 4 participants 4 messages Jun 4, 2021 – Jun 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-user-gpu: reorder free calls.

Free in correct order to avoid use-after-free.

Resolves: CID 1453812

---
 contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/vhost-user-gpu/vhost-user-gpu.c +1 -1
index 6dc6a44f4e26..611360e6b475 100644
@@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
     if (!res->image) {
         g_critical("%s: resource creation failed %d %d %d",
                    __func__, c2d.resource_id, c2d.width, c2d.height);
-        g_free(res);
         vugbm_buffer_destroy(&res->buffer);
+        g_free(res);
         cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
         return;
     }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Gerd Hoffmann

Free in correct order to avoid use-after-free.

Resolves: CID 1453812

---

Quoted 23 lines
 contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/vhost-user-gpu/vhost-user-gpu.c +1 -2
index 6dc6a44f4e26..611360e6b475 100644
@@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
     if (!res->image) {
         g_critical("%s: resource creation failed %d %d %d",
                    __func__, c2d.resource_id, c2d.width, c2d.height);
-        g_free(res);
         vugbm_buffer_destroy(&res->buffer);
+        g_free(res);
         cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
         return;
     }
--

2.31.1

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#3 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann <[email protected]> 于2021年6月4日周五 下午6:37写道:

Free in correct order to avoid use-after-free.

Resolves: CID 1453812

Sorry, my fault.

Quoted 22 lines
---
 contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/vhost-user-gpu/vhost-user-gpu.c +1 -2
index 6dc6a44f4e26..611360e6b475 100644
@@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
     if (!res->image) {
         g_critical("%s: resource creation failed %d %d %d",
                    __func__, c2d.resource_id, c2d.width, c2d.height);
-        g_free(res);
         vugbm_buffer_destroy(&res->buffer);
+        g_free(res);
         cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
         return;
     }
--

2.31.1