From: Rafal Wojtczuk Subject: Two small patches related to xenfb Date: Fri, 26 Sep 2008 16:05:48 +0200 Message-ID: <20080926140548.GC31985@emperor2.home.aster.pl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6sX45UoQRIJXqkqR" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline 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 --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="row_stride_div0.patch" --- xen-3.2-testing.hg/tools/ioemu/hw/xenfb.c.orig 2008-09-26 11:16:55.000000000 +0200 +++ xen-3.2-testing.hg/tools/ioemu/hw/xenfb.c 2008-09-26 11:18:01.000000000 +0200 @@ -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; --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="vnc_resize_doublecheck.patch" --- xen-3.2-testing.hg/tools/ioemu/vnc.c.orig 2008-09-26 11:14:21.000000000 +0200 +++ xen-3.2-testing.hg/tools/ioemu/vnc.c 2008-09-26 11:37:25.000000000 +0200 @@ -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])); --6sX45UoQRIJXqkqR Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --6sX45UoQRIJXqkqR--