Skip to contentSkip to conversation

ui/vnc.c: Fix crash with VNC

PATCH In review Gerhard Wiesinger 8 participants 21 messages Nov 1, 2012 – Nov 12, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/vnc.c: Fix crash with VNC

Fix crash with VNC under NT 4.0 and VMWare VGA and window which is outside of the visible area.

Backtrace:
#0  set_bit (addr=<optimized out>, nr=-3) at ./bitops.h:122
#1  vnc_dpy_update (ds=<optimized out>, x=-48, y=145, w=57, h=161) at ui/vnc.c:452
#2  0x00007f1ce057e2ec in dpy_update (s=0x7f1ce1c8c880, h=16, w=66, y=145, x=-57) at ./console.h:242
#3  vmsvga_update_rect (h=16, w=66, y=145, x=-57, s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:324
#4  vmsvga_update_rect_flush (s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:357
#5  vmsvga_update_display (opaque=0x7f1ce1cb3dd0) at hw/vmware_vga.c:960
#6  0x00007f1ce05f0b37 in vnc_refresh (opaque=0x7f1cd8526010) at ui/vnc.c:2590
#7  0x00007f1ce05c002b in qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:392
#8  qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:373
#9  0x00007f1ce05c028d in qemu_run_all_timers () at qemu-timer.c:449

#10 0x00007f1ce058f2ee in main_loop_wait (nonblocking=<optimized out>) at main-loop.c:502 #11 0x00007f1ce047acb3 in main_loop () at vl.c:1655
#12 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:3826

---
 ui/vnc.c | 5 +++++
 1 file changed, 5 insertions(+)
ui/vnc.c +5 -0
index 7c120e6..ae6d819 100644
@@ -453,6 +453,11 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
     w = MIN(x + w, width) - x;
     h = MIN(h, height);
 
+    x = MAX(x, 0);
+    y = MAX(y, 0);
+    w = MAX(w, 0);
+    h = MAX(h, 0);
+
     for (; y < h; y++)
         for (i = 0; i < w; i += 16)
             set_bit((x + i) / 16, s->dirty[y]);
Signature · 1 line
1.7.11.7
#1 lore raw

Ping?

Quoted 39 lines · Gerhard Wiesinger

Fix crash with VNC under NT 4.0 and VMWare VGA and window which is outside of the visible area.

Backtrace:
#0  set_bit (addr=<optimized out>, nr=-3) at ./bitops.h:122
#1  vnc_dpy_update (ds=<optimized out>, x=-48, y=145, w=57, h=161) at ui/vnc.c:452
#2  0x00007f1ce057e2ec in dpy_update (s=0x7f1ce1c8c880, h=16, w=66, y=145, x=-57) at ./console.h:242
#3  vmsvga_update_rect (h=16, w=66, y=145, x=-57, s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:324
#4  vmsvga_update_rect_flush (s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:357
#5  vmsvga_update_display (opaque=0x7f1ce1cb3dd0) at hw/vmware_vga.c:960
#6  0x00007f1ce05f0b37 in vnc_refresh (opaque=0x7f1cd8526010) at ui/vnc.c:2590
#7  0x00007f1ce05c002b in qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:392
#8  qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:373
#9  0x00007f1ce05c028d in qemu_run_all_timers () at qemu-timer.c:449

#10 0x00007f1ce058f2ee in main_loop_wait (nonblocking=<optimized out>) at main-loop.c:502 #11 0x00007f1ce047acb3 in main_loop () at vl.c:1655
#12 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:3826

---
 ui/vnc.c | 5 +++++
 1 file changed, 5 insertions(+)
ui/vnc.c +5 -0
index 7c120e6..ae6d819 100644
@@ -453,6 +453,11 @@ static void vnc_dpy_update(DisplayState *ds, int 
 x, int y, int w, int h)
     w = MIN(x + w, width) - x;
     h = MIN(h, height);
 
+    x = MAX(x, 0);
+    y = MAX(y, 0);
+    w = MAX(w, 0);
+    h = MAX(h, 0);
+
     for (; y < h; y++)
         for (i = 0; i < w; i += 16)
             set_bit((x + i) / 16, s->dirty[y]);
#2 lore raw

Yet another ping.

Ciao,
Gerhard

Quoted 44 lines · Gerhard Wiesinger

Ping?

Quoted 39 lines · Gerhard Wiesinger

Fix crash with VNC under NT 4.0 and VMWare VGA and window which is outside of the visible area.

Backtrace:
#0  set_bit (addr=<optimized out>, nr=-3) at ./bitops.h:122
#1  vnc_dpy_update (ds=<optimized out>, x=-48, y=145, w=57, h=161) at ui/vnc.c:452
#2  0x00007f1ce057e2ec in dpy_update (s=0x7f1ce1c8c880, h=16, w=66, y=145, x=-57) at ./console.h:242
#3  vmsvga_update_rect (h=16, w=66, y=145, x=-57, s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:324
#4  vmsvga_update_rect_flush (s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:357
#5  vmsvga_update_display (opaque=0x7f1ce1cb3dd0) at hw/vmware_vga.c:960
#6  0x00007f1ce05f0b37 in vnc_refresh (opaque=0x7f1cd8526010) at ui/vnc.c:2590
#7  0x00007f1ce05c002b in qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:392
#8  qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:373
#9  0x00007f1ce05c028d in qemu_run_all_timers () at qemu-timer.c:449

#10 0x00007f1ce058f2ee in main_loop_wait (nonblocking=<optimized out>) at main-loop.c:502 #11 0x00007f1ce047acb3 in main_loop () at vl.c:1655
#12 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:3826

---
 ui/vnc.c | 5 +++++
 1 file changed, 5 insertions(+)
ui/vnc.c +5 -0
index 7c120e6..ae6d819 100644
@@ -453,6 +453,11 @@ static void vnc_dpy_update(DisplayState *ds, int 
 x, int y, int w, int h)
     w = MIN(x + w, width) - x;
     h = MIN(h, height);
 
+    x = MAX(x, 0);
+    y = MAX(y, 0);
+    w = MAX(w, 0);
+    h = MAX(h, 0);
+
     for (; y < h; y++)
         for (i = 0; i < w; i += 16)
             set_bit((x + i) / 16, s->dirty[y]);
#3 lore raw
In reply to Gerhard Wiesinger
Quoted 47 lines · Gerhard Wiesinger

Fix crash with VNC under NT 4.0 and VMWare VGA and window which is outside of the visible area.

Backtrace:

#0 set_bit (addr=<optimized out>, nr=-3) at ./bitops.h:122
#1 vnc_dpy_update (ds=<optimized out>, x=-48, y=145, w=57, h=161) at ui/vnc.c:452
#2 0x00007f1ce057e2ec in dpy_update (s=0x7f1ce1c8c880, h=16, w=66, y=145, x=-57) at ./console.h:242
#3 vmsvga_update_rect (h=16, w=66, y=145, x=-57, s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:324

#4  vmsvga_update_rect_flush (s=0x7f1ce1cb3dd0) at hw/vmware_vga.c:357
#5  vmsvga_update_display (opaque=0x7f1ce1cb3dd0) at hw/vmware_vga.c:960
#6  0x00007f1ce05f0b37 in vnc_refresh (opaque=0x7f1cd8526010) at

ui/vnc.c:2590
#7 0x00007f1ce05c002b in qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:392
#8 qemu_run_timers (clock=0x7f1ce1c4f910) at qemu-timer.c:373 #9 0x00007f1ce05c028d in qemu_run_all_timers () at qemu-timer.c:449 #10 0x00007f1ce058f2ee in main_loop_wait (nonblocking=<optimized out>) at main-loop.c:502
#11 0x00007f1ce047acb3 in main_loop () at vl.c:1655
#12 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:3826

---
 ui/vnc.c | 5 +++++
 1 file changed, 5 insertions(+)
ui/vnc.c +5 -0
index 7c120e6..ae6d819 100644
@@ -453,6 +453,11 @@ static void vnc_dpy_update(DisplayState *ds, int x, int
 y, int w, int h)
     w = MIN(x + w, width) - x;
     h = MIN(h, height);
 
+    x = MAX(x, 0);
+    y = MAX(y, 0);
+    w = MAX(w, 0);
+    h = MAX(h, 0);
+
     for (; y < h; y++)
         for (i = 0; i < w; i += 16)
             set_bit((x + i) / 16, s->dirty[y]);
Quoted 2 lines

--
1.7.11.7

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

-- PMM

#4 lore raw

Hi,

Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

cheers,
Gerd

#5 lore raw
Quoted 9 lines · Gerd Hoffmann
Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

Would the attached patch help?

Regards,
BALATON Zoltan

From e1ea12f3fa70298f630c0b829d0f304339ca9799 Mon Sep 17 00:00:00 2001
From: BALATON Zoltan <[email protected]>
Date: Fri, 9 Nov 2012 00:44:29 +0100
Subject: [PATCH 2/2] vmware_vga: Clip updates with negative out of range
rects to visible area

Added checks and clipping also for negative out of range values in update rects which have been seen to happen at least with VNC under Windows NT 4.0 when a window is outside the visible area.

---
 hw/vmware_vga.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/vmware_vga.c +16 -0
index 834588d..e59ab3a 100644
@@ -296,6 +296,14 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
     uint8_t *src;
     uint8_t *dst;
 
+    if (x < 0 || x + w < 0) {
+        fprintf(stderr, "%s: update negative x position: %d, w: %d\n",
+                __func__, x, w);
+        w -= x;
+        x = MAX(x, 0);
+        y = MAX(w, 0);
+    }
+
     if (x + w > ds_get_width(s->vga.ds)) {
         fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
                 __func__, x, w);
@@ -303,6 +311,14 @@ static inline void vmsvga_update_rect(struct vmsvga_state_s *s,
         w = ds_get_width(s->vga.ds) - x;
     }
 
+    if (y < 0 || y + h < 0) {
+        fprintf(stderr, "%s: update negative y position: %d, h: %d\n",
+                __func__, y, h);
+        h -= y;
+        y = MAX(y, 0);
+        h = MAX(h, 0);
+    }
+
     if (y + h > ds_get_height(s->vga.ds)) {
         fprintf(stderr, "%s: update height too large y: %d, h: %d\n",
                 __func__, y, h);
Signature · 1 line
1.7.10
#8 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann
   Hi,
Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

Regarding fail safe programming I think it should be fixed/handled in both modules:
vmware_vga.c should not trigger wrong values but also other modules should verify or even correct there input parameters. (think of situations where bits might not be accurate due to CPU bugs or even QEMU/KVM in aerospace where bits fall to other states due to high energy cosmic ray).

Best solution is IHMO for vnc.c:
1.) Log the problem (that other modules can be fixed, too). 2.) Fix parameters (so that program doesn't crash)

In mission critical software application like aerospace, airplanes, cars, etc. (e.g. where people might get unhealthy) handling such situations where input parameters aren't as expected is a must.

See:
https://en.wikipedia.org/wiki/Fail-safe
https://en.wikipedia.org/wiki/Cosmic_ray#Effect_on_electronics
https://en.wikipedia.org/wiki/Radiation_hardening

Precondition:
https://en.wikipedia.org/wiki/Eiffel_%28programming_language%29#Design_by_Contract

Ciao,
Gerhard

#9 lore raw
Quoted 3 lines · Gerhard Wiesinger

(think of situations where bits might not be accurate due to CPU bugs or even QEMU/KVM in aerospace where
bits fall to other states due to high energy cosmic ray).

If any aeroplane manufacturer is using QEMU for some safety critical purpose it would be nice if they'd let us know. I could then avoid flying with them in future :-)

-- PMM

#6 lore raw
In reply to BALATON Zoltan
Quoted 8 lines · BALATON Zoltan
Quoted 7 lines · Gerd Hoffmann
Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Quoted 4 lines
Quoted 2 lines

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

Would the attached patch help?

I fixed this 2 times, and I remember two other people fixing the same thing too already. Lemme find some refs...

thread.gmane.org/gmane.comp.emulators.qemu/166064

---
Is it the same as https://bugs.launchpad.net/bugs/918791 ? At least it appears to be the same theme... But there,
the patch (https://launchpadlibrarian.net/94916786/qemu-vmware.debdiff)
also updates width/height. My comment:
https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791/comments/21
---

Adding some Cc's....

#7 lore raw
Quoted 19 lines · Michael Tokarev
Quoted 8 lines · BALATON Zoltan
Quoted 7 lines · Gerd Hoffmann
Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Quoted 4 lines
Quoted 2 lines

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

Would the attached patch help?

I fixed this 2 times, and I remember two other people fixing the same thing too already. Lemme find some refs...

http://thread.gmane.org/gmane.comp.emulators.qemu/166064

Quoted 7 lines

---
Is it the same as https://bugs.launchpad.net/bugs/918791 ? At least it appears to be the same theme... But there,
the patch (https://launchpadlibrarian.net/94916786/qemu-vmware.debdiff)
also updates width/height. My comment:
https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/918791/comments/21
---

Another reference: the same problem in qxl (Gerd should know this area):

http://thread.gmane.org/gmane.comp.emulators.qemu/171093

this patch is a cleanup, -- the problem has been fixed twice in a row in qxl. We've 3 fixes for it in vmware now too.

So figuring out the proper level where to fix it is important...

/mjt

#10 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell
Quoted 3 lines · Gerhard Wiesinger

(think of situations where bits might not be accurate due to CPU bugs or even QEMU/KVM in aerospace where
bits fall to other states due to high energy cosmic ray).

If any aeroplane manufacturer is using QEMU for some safety critical purpose it would be nice if they'd let us know. I could then avoid flying with them in future :-)

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Regards,

Anthony Liguori

Quoted 2 lines

-- PMM

#11 lore raw
Quoted 2 lines · Anthony Liguori

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Defensive programming would suggest doing the clipping in the console.c layer. That sounds a reasonable plan to me (especially if we've hit similar problems multiple times in the past).

-- PMM

#12 lore raw
Quoted 7 lines · Peter Maydell
Quoted 2 lines · Anthony Liguori

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Defensive programming would suggest doing the clipping in the console.c layer. That sounds a reasonable plan to me (especially if we've hit similar problems multiple times in the past).

Fully agree, I'll cook up a patch as I'm touching that anyway.

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

cheers,
Gerd

#13 lore raw

Dear Gerd Hoffmann,

Quoted 9 lines · Peter Maydell
Quoted 7 lines · Anthony Liguori
Quoted 2 lines

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Defensive programming would suggest doing the clipping in the console.c layer. That sounds a reasonable plan to me (especially if we've hit similar problems multiple times in the past).

Quoted 6 lines

Fully agree, I'll cook up a patch as I'm touching that anyway.

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Or rather some revisions of the guest X driver. Though it's worth investigating it in the right place indeed.

Quoted 2 lines

cheers,
Gerd

Best regards,
Marek Vasut

#14 lore raw
Quoted 7 lines · Marek Vasut
Quoted 4 lines · Gerd Hoffmann

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Or rather some revisions of the guest X driver.

If qemu's vmware-vga is blithely trusting what the guest driver hands it then that is itself a bug...

To answer Gerd's question, I think I'd go for clip rather than assert (especially at this point in the release cycle), though I don't feel very strongly about it.

-- PMM

#15 lore raw
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Marek Vasut
Quoted 4 lines · Gerd Hoffmann

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Quoted 7 lines
Quoted 1 line

Or rather some revisions of the guest X driver.

If qemu's vmware-vga is blithely trusting what the guest driver hands it then that is itself a bug...

To answer Gerd's question, I think I'd go for clip rather than assert (especially at this point in the release cycle), though I don't feel very strongly about it.

I'd go for clipping rather than asserting too (no crash) in all layers as a defensive approach (console.c/vnc.c). Additionally logging that condition would be helpful that the arising bug (which occurred several times with a lot of unapplied fixes) can be detected by users easily and fixed accordingly.

Ciao,
Gerhard

#20 lore raw
In reply to Gerhard Wiesinger
Quoted 23 lines · Gerhard Wiesinger
Quoted 10 lines · Gerd Hoffmann
   Hi,
Quoted 6 lines

I think this is fixing this at the wrong level. Either we should require that drivers (in this case vmware_vga.c) must not call dpy_gfx_update() with out of range values, or we should do the clipping in the console.c layer, but I don't think requiring every UI backend to clip is the right thing. Anthony?

Quoted 3 lines

Agree. IMHO vmware_vga.c is at fault here and should be fixed. We can add some asserts to console.[ch] to enforce this ...

Regarding fail safe programming I think it should be fixed/handled in both modules:
vmware_vga.c should not trigger wrong values but also other modules should verify or even correct there input parameters.
(think of situations where bits might not be accurate due to CPU bugs or even QEMU/KVM in aerospace where
bits fall to other states due to high energy cosmic ray).

Quoted 7 lines

Best solution is IHMO for vnc.c:
1.) Log the problem (that other modules can be fixed, too). 2.) Fix parameters (so that program doesn't crash)

In mission critical software application like aerospace, airplanes, cars, etc. (e.g. where people might get unhealthy) handling such situations where input parameters aren't as expected is a must.

There are plenty of other considerations. For example, QEMU tests don't have 100% code coverage, without even considering MC/DC. Adding two overlapping checks could even result in <100% coverage.

Another issue is that the guest may cause QEMU to abort().

The code has not been formally reviewed, it's known to be in violation to the few specifications we have (HACKING, CODING_STYLE, docs/*).

While QEMU is obviously a fine solution for many real world problems, I don't recommend using QEMU for any safety critical tasks.

Quoted 12 lines

See:
https://en.wikipedia.org/wiki/Fail-safe
https://en.wikipedia.org/wiki/Cosmic_ray#Effect_on_electronics
https://en.wikipedia.org/wiki/Radiation_hardening

Precondition:
https://en.wikipedia.org/wiki/Eiffel_%28programming_language%29#Design_by_Contract

Ciao,
Gerhard

#16 lore raw
In reply to Gerhard Wiesinger

Dear Gerhard Wiesinger,

Quoted 13 lines · Peter Maydell
Quoted 12 lines · Marek Vasut
Quoted 7 lines
Quoted 4 lines · Gerd Hoffmann

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Or rather some revisions of the guest X driver.

If qemu's vmware-vga is blithely trusting what the guest driver hands it then that is itself a bug...

Quoted 6 lines
Quoted 3 lines

To answer Gerd's question, I think I'd go for clip rather than assert (especially at this point in the release cycle), though I don't feel very strongly about it.

I'd go for clipping rather than asserting too (no crash) in all layers as a defensive approach (console.c/vnc.c).

Won't that be an unnecessary slowdown?

Quoted 4 lines

Additionally logging that
condition would be helpful that the arising bug (which occurred several times with a lot of unapplied fixes) can be detected by users easily and fixed accordingly.

Sounds good.

Quoted 2 lines

Ciao,
Gerhard

Best regards,
Marek Vasut

#18 lore raw
In reply to Marek Vasut
Quoted 13 lines · Marek Vasut

Dear Gerd Hoffmann,

Quoted 11 lines · Peter Maydell
Quoted 7 lines · Anthony Liguori
Quoted 2 lines

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Defensive programming would suggest doing the clipping in the console.c layer. That sounds a reasonable plan to me (especially if we've hit similar problems multiple times in the past).

Fully agree, I'll cook up a patch as I'm touching that anyway.

Quoted 7 lines
Quoted 4 lines

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Or rather some revisions of the guest X driver. Though it's worth investigating it in the right place indeed.

That too, but we must add a check to qemu nevertheless. We can't trust the guest to not pass in bogous data, be it intentionally or by mistake.
vmware-vga must sanity check the guest input no matter what, but
validating the guests input once should be enougth.

cheers,
Gerd

#17 lore raw
In reply to Marek Vasut

Hi,

Quoted 4 lines
Quoted 2 lines

I'd go for clipping rather than asserting too (no crash) in all layers as a defensive approach (console.c/vnc.c).

Won't that be an unnecessary slowdown?

Thats why I tend to prefer assert for additional sanity checks. They help finding bugs, but can optionally be compiled out.

But adding new asserts just before a release isn't the smartest move indeed, maybe clip now and turn the checks into asserts once 1.3 is out of the door.

cheers,
Gerd

#19 lore raw
In reply to Gerd Hoffmann
Quoted 19 lines · Gerd Hoffmann
Quoted 18 lines · Marek Vasut

Dear Gerd Hoffmann,

Quoted 15 lines · Peter Maydell
Quoted 7 lines · Anthony Liguori
Quoted 2 lines

While the abstract discussion is fun, it never hurts to be defensive. I agree the root cause is vmware-vga but checking in vnc doesn't hurt.

Defensive programming would suggest doing the clipping in the console.c layer. That sounds a reasonable plan to me (especially if we've hit similar problems multiple times in the past).

Fully agree, I'll cook up a patch as I'm touching that anyway.

Question is just whenever we'll go silently fixup stuff in console.c or use assert()s to enforce callers getting this correct. I'd tend to use assert() as vmware-vga passing bogous stuff there IMHO indicates there is a bug in vmware-vga.

Quoted 7 lines
Quoted 2 lines

Or rather some revisions of the guest X driver. Though it's worth investigating it in the right place indeed.

That too, but we must add a check to qemu nevertheless. We can't trust the guest to not pass in bogous data, be it intentionally or by mistake. vmware-vga must sanity check the guest input no matter what, but validating the guests input once should be enougth.

For vmware_vga you could take this:
http://patchwork.ozlabs.org/patch/197904/
or modify it/come up with a similar patch as needed.

Regards,
BALATON Zoltan