Skip to contentSkip to conversation

Two small patches related to xenfb

PATCH Rafal Wojtczuk 3 participants 3 messages Sep 26, 2008 – Sep 29, 2008

lore
Share & tools
lore
#0 lore raw

Hello,
Two minor issues:
row_stride_div0.patch: a malicious frontend can send row_stride==0 and force qemu-dm to perform division by 0
vnc_resize_doublecheck.patch: there is an unchecked multiplication when calculating framebuffer size. Cs 17630 sanitizes framebuffer dimensions passed by the frontend, so most probably no integer overflow can happen, but there should be a check for overflow close to the actual computation (to make code review easier and to cope with other codepaths in the future).

Diffs against xen-3.2-testing.hg.

Regards,
Rafal Wojtczuk
Principal Researcher
Invisible Things Lab

tools/ioemu/hw/xenfb.c renamed from tools/ioemu/hw/xenfb.c.orig +1 -1
@@ -496,7 +496,7 @@
 			depth);
 		return -1;
 	}
-	if (row_stride < 0 || row_stride > fb_len) {
+	if (row_stride <= 0 || row_stride > fb_len) {
 		fprintf(stderr,
 			"FB: invalid frontend stride %d\n", row_stride);
 		return -1;
tools/ioemu/vnc.c renamed from tools/ioemu/vnc.c.orig +11 -1
@@ -329,13 +329,23 @@
 
     vnc_write_s32(vs, encoding);
 }
-
+static int mult_overflows(int x, int y)
+{
+    if (x<=0 || y<=0 || x*y<=0 || x>((unsigned int)(-1))/y)
+        return 1;
+    else return 0;
+}
 static void vnc_dpy_resize(DisplayState *ds, int w, int h)
 {
     int size_changed;
     VncState *vs = ds->opaque;
     int o;
 
+    if (mult_overflows(w, h) || mult_overflows(w*h, vs->depth) ||
+        mult_overflows(h, sizeof(vs->dirty_row[0])) {
+        fprintf(stderr, "vnc: suspicious vnc_dpy_resize arguments, exiting\n");
+        exit(1);
+    }
     ds->data = realloc(ds->data, w * h * vs->depth);
     vs->old_data = realloc(vs->old_data, w * h * vs->depth);
     vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Rafal Wojtczuk writes ("[Xen-devel] Two small patches related to xenfb"):

Quoted 8 lines

Two minor issues:
row_stride_div0.patch: a malicious frontend can send row_stride==0 and force qemu-dm to perform division by 0
vnc_resize_doublecheck.patch: there is an unchecked multiplication when calculating framebuffer size. Cs 17630 sanitizes framebuffer dimensions passed by the frontend, so most probably no integer overflow can happen, but there should be a check for overflow close to the actual computation (to make code review easier and to cope with other codepaths in the future).

Thanks. Your patch wasn't quite right in a couple of ways but I have fixed it up and applied it to qemu-xen-unstable. I'll cherry pick it into 3.3 after I get a successful test run.

Quoted 1 line

Diffs against xen-3.2-testing.hg.

Thanks but xen-3.2 is pretty much out of our support life cycle now. We would suggest you use 3.3 instead.

tools/ioemu/vnc.c line 334

Quoted 3 lines
tools/ioemu/vnc.c renamed from tools/ioemu/vnc.c.orig +3 -0
+static int mult_overflows(int x, int y)
+{
+    if (x<=0 || y<=0 || x*y<=0 || x>((unsigned int)(-1))/y)

This isn't correct.
* The use of (unsigned int)(-1) is strange; you should use INT_MAX (and not ~(unsigned int)0 either, as we wanted the figure for _signed_ overflow).
* Multiplying x*y is undefined behaviour if it's an overflow; that can in theory lead the compiler to `prove' that you know that there is no overflow and conclude that the other tests cannot fail. You should not do this test at all. The division is sufficient.

tools/ioemu/vnc.c line 345

Quoted 2 lines
tools/ioemu/vnc.c renamed from tools/ioemu/vnc.c.orig +2 -0
+    if (mult_overflows(w, h) || mult_overflows(w*h, vs->depth) ||
+        mult_overflows(h, sizeof(vs->dirty_row[0])) {

Evidently you didn't compile this because it has a missing parenthesis.

Also, you should include a Signed-Off-By line like this

except with your name and email address. This indicates that you are certifying the code as suitable (copyright-wise and so on) for inclusion in Xen. You can find the precise meaning in the Linux upstream kernel tree (Documentation/SubmittingPatches).

In this case, and since your patch was so small, I took your message to grant the relevant permissions.

Ian.

Quoted 1 line

From Documentation/SubmittingPatches:

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

#2 lore raw
In reply to Rafal Wojtczuk
Quoted 4 lines · Rafal Wojtczuk

Hello,
Two minor issues:
row_stride_div0.patch: a malicious frontend can send row_stride==0 and force qemu-dm to perform division by 0

Ok.

Quoted 5 lines

vnc_resize_doublecheck.patch: there is an unchecked multiplication when calculating framebuffer size. Cs 17630 sanitizes framebuffer dimensions passed by the frontend, so most probably no integer overflow can happen, but there should be a check for overflow close to the actual computation (to make code review easier and to cope with other codepaths in the future).

If bogous values can make it through the sanity checks in xenfb_configure_fb() then those sanity checks must be fixed.

Adding another check somewhere else certainly doesn't make review easier. In contrast it makes error handling more complicated because there are multiple places where you have to deal with errors instead of just one functions which does all sanity checks.

cheers,
Gerd