Skip to contentSkip to conversation

fix crashes with vmware driver

RFC In review Serge Hallyn 4 participants 5 messages Mar 2, 2012 – Mar 11, 2012

lore
Share & tools
lore
#0 lore raw

RFC 1/1 fix crashes with vmware driver

Hi,

I don't know where the best place to catch this would be, but with vnc and vmware_vga it's possible to get set_bit called on a negative index, crashing qemu. See

https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791

for details. This patch prevents that. It's possible this should be caught earlier, but this patch works for me.

---
 vmware_vga.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/vmware_vga.c +16 -0
Index: qemu-kvm-1.0+noroms/hw/vmware_vga.c
===================================================================
@@ -298,6 +298,22 @@
     uint8_t *src;
     uint8_t *dst;
 
+    if (x < 0) {
+        fprintf(stderr, "%s: update x was < 0 (%d, w %d)\n",
+                        __FUNCTION__, x, w);
+        w += x;
+	if (w < 0)
+		return;
+        x = 0;
+    }
+    if (y < 0) {
+        fprintf(stderr, "%s: update y was < 0 (%d, h %d)\n",
+                        __FUNCTION__, y, h);
+        h += y;
+	if (h < 0)
+		return;
+        y = 0;
+    }
     if (x + w > s->width) {
         fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                         __FUNCTION__, x, w);
#1 lore raw
Quoted 30 lines · Serge Hallyn

Hi,

I don't know where the best place to catch this would be, but with vnc and vmware_vga it's possible to get set_bit called on a negative index, crashing qemu. See

https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791

for details. This patch prevents that. It's possible this should be caught earlier, but this patch works for me.

---
 vmware_vga.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Index: qemu-kvm-1.0+noroms/hw/vmware_vga.c
===================================================================

hw/vmware_vga.c +6 -0
@@ -298,6 +298,22 @@
     uint8_t *src;
     uint8_t *dst;
 
+    if (x < 0) {
+        fprintf(stderr, "%s: update x was < 0 (%d, w %d)\n",
+                        __FUNCTION__, x, w);
+        w += x;
+	if (w < 0)
+		return;

hw/vmware_vga.c line 316

Quoted 10 lines
hw/vmware_vga.c +10 -0
+        x = 0;
+    }
+    if (y < 0) {
+        fprintf(stderr, "%s: update y was < 0 (%d, h %d)\n",
+                        __FUNCTION__, y, h);
+        h += y;
+	if (h < 0)
+		return;
+        y = 0;
+    }

Looks like it has mixed spaces and tabs.

CODING_STYLE wants {} on all if's

Quoted 3 lines
hw/vmware_vga.c +0 -0
     if (x + w > s->width) {
         fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                         __FUNCTION__, x, w);
Signature · 4 lines
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
[email protected]
#2 lore raw

PATCH 1/1 vmware_vga: stop crashing

if x or y < 0, set them to 0 (and decrement width/height accordingly)>

I don't know where the best place to catch this would be, but with vnc and vmware_vga it's possible to get set_bit called on a negative index, crashing qemu. See

https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791

for details. This patch prevents that. It's possible this should be caught earlier, but this patch works for me.

Changelog:
Mar 5: As Ryan Harper pointed out, don't mix tabs+spaces,
and put {} around all conditionals.

---
 hw/vmware_vga.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
hw/vmware_vga.c +18 -0
index 142d9f4..c94f9f3 100644
@@ -298,6 +298,24 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
     uint8_t *src;
     uint8_t *dst;
 
+    if (x < 0) {
+        fprintf(stderr, "%s: update x was < 0 (%d, w %d)\n",
+                        __FUNCTION__, x, w);
+        w += x;
+        if (w < 0) {
+            return;
+        }
+        x = 0;
+    }
+    if (y < 0) {
+        fprintf(stderr, "%s: update y was < 0 (%d, h %d)\n",
+                        __FUNCTION__, y, h);
+        h += y;
+        if (h < 0) {
+            return;
+        }
+        y = 0;
+    }
     if (x + w > s->width) {
         fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                         __FUNCTION__, x, w);
Signature · 1 line
1.7.9
#4 lore raw
In reply to Ryan Harper

Thanks. As there's been no substantial feedback, I'll resend with those changes.

-serge

Quoted 58 lines · Ryan Harper
Quoted 30 lines · Serge Hallyn

Hi,

I don't know where the best place to catch this would be, but with vnc and vmware_vga it's possible to get set_bit called on a negative index, crashing qemu. See

https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791

for details. This patch prevents that. It's possible this should be caught earlier, but this patch works for me.

---
 vmware_vga.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Index: qemu-kvm-1.0+noroms/hw/vmware_vga.c
===================================================================

hw/vmware_vga.c +6 -0
@@ -298,6 +298,22 @@
     uint8_t *src;
     uint8_t *dst;
 
+    if (x < 0) {
+        fprintf(stderr, "%s: update x was < 0 (%d, w %d)\n",
+                        __FUNCTION__, x, w);
+        w += x;
+	if (w < 0)
+		return;

hw/vmware_vga.c line 316

Quoted 10 lines
hw/vmware_vga.c +10 -0
+        x = 0;
+    }
+    if (y < 0) {
+        fprintf(stderr, "%s: update y was < 0 (%d, h %d)\n",
+                        __FUNCTION__, y, h);
+        h += y;
+	if (h < 0)
+		return;
+        y = 0;
+    }

Looks like it has mixed spaces and tabs.

CODING_STYLE wants {} on all if's

Quoted 3 lines
hw/vmware_vga.c +0 -0
     if (x + w > s->width) {
         fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                         __FUNCTION__, x, w);
Signature · 4 lines
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
[email protected]
Tested-by on v1 1/1
#3 lore raw

Re: [Qemu-devel] [PATCH 1/1] vmware_vga: stop crashing

In reply to Serge Hallyn

Can confirm that this patch fixes a crash which also occoured here. Since window was out of the VNC window, crash was reproduceable and has been removed reproduceable.

Please apply ASAP.

Ciao,
Gerhard

--
http://www.wiesinger.com/

Quoted 55 lines · Serge Hallyn

if x or y < 0, set them to 0 (and decrement width/height accordingly)>

I don't know where the best place to catch this would be, but with vnc and vmware_vga it's possible to get set_bit called on a negative index, crashing qemu. See

https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791

for details. This patch prevents that. It's possible this should be caught earlier, but this patch works for me.

Changelog:
Mar 5: As Ryan Harper pointed out, don't mix tabs+spaces,
and put {} around all conditionals.

---
hw/vmware_vga.c | 18 ++++++++++++++++++

1 files changed, 18 insertions(+), 0 deletions(-)
hw/vmware_vga.c +18 -0
index 142d9f4..c94f9f3 100644
@@ -298,6 +298,24 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
    uint8_t *src;
    uint8_t *dst;
 
+    if (x < 0) {
+        fprintf(stderr, "%s: update x was < 0 (%d, w %d)\n",
+                        __FUNCTION__, x, w);
+        w += x;
+        if (w < 0) {
+            return;
+        }
+        x = 0;
+    }
+    if (y < 0) {
+        fprintf(stderr, "%s: update y was < 0 (%d, h %d)\n",
+                        __FUNCTION__, y, h);
+        h += y;
+        if (h < 0) {
+            return;
+        }
+        y = 0;
+    }
    if (x + w > s->width) {
        fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                        __FUNCTION__, x, w);
Signature · 1 line
1.7.9