Skip to contentSkip to conversation

virtio-gpu: check if the resource already exists in virtio_gpu_load()

PATCH In review Li Qiang 3 participants 3 messages Jun 28, 2019 – Aug 26, 2019

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 virtio-gpu: check if the resource already exists in virtio_gpu_load()

While loading virtio-gpu, the data can be malicious, we should check if the resource already exists.

---
 hw/display/virtio-gpu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/display/virtio-gpu.c +5 -0
index 2b0f66b1d6..f1ebed9959 100644
@@ -1002,6 +1002,11 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
 
     resource_id = qemu_get_be32(f);
     while (resource_id != 0) {
+        res = virtio_gpu_find_resource(g, resource_id);
+        if (res) {
+            return -EINVAL;
+        }
+
         res = g_new0(struct virtio_gpu_simple_resource, 1);
         res->resource_id = resource_id;
         res->width = qemu_get_be32(f);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Li Qiang

While loading virtio-gpu, the data can be malicious, we should check if the resource already exists.

Quoted 25 lines
---
 hw/display/virtio-gpu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/display/virtio-gpu.c +5 -1
index 2b0f66b1d6..f1ebed9959 100644
@@ -1002,6 +1002,11 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
 
     resource_id = qemu_get_be32(f);
     while (resource_id != 0) {
+        res = virtio_gpu_find_resource(g, resource_id);
+        if (res) {
+            return -EINVAL;
+        }
+
         res = g_new0(struct virtio_gpu_simple_resource, 1);
         res->resource_id = resource_id;
         res->width = qemu_get_be32(f);
--

2.17.1

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Li Qiang
Quoted 13 lines · Li Qiang

While loading virtio-gpu, the data can be malicious, we should check if the resource already exists.

---
 hw/display/virtio-gpu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/display/virtio-gpu.c +0 -0
index 2b0f66b1d6..f1ebed9959 100644

hw/display/virtio-gpu.c static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, · line 1007

Quoted 6 lines
hw/display/virtio-gpu.c +3 -0
@@ -1002,6 +1002,11 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
 
     resource_id = qemu_get_be32(f);
     while (resource_id != 0) {
+        res = virtio_gpu_find_resource(g, resource_id);
+        if (res) {
+            return -EINVAL;

EEXIST?

/mjt