]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
xenfb.c: avoid expensive loops when prod <= out_cons
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Wed, 6 Jan 2016 16:32:22 +0000 (16:32 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Mon, 25 Apr 2016 10:12:57 +0000 (11:12 +0100)
If the frontend sets out_cons to a value higher than out_prod, it will
cause xenfb_handle_events to loop about 2^32 times. Avoid that by using
better checks at the beginning of the function.

upstream-commit-id: ac0487e1d2ae811cd4d035741a109a4ecfb013f1

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reported-by: Ling Liu <liuling-it@360.cn>
hw/display/xenfb.c

index 7baacbe29e157caccc3aaf1a8cbf348c27014e63..56d1a365117f46baf56bd7dd58201e1147a5dda6 100644 (file)
@@ -784,8 +784,9 @@ static void xenfb_handle_events(struct XenFB *xenfb)
 
     prod = page->out_prod;
     out_cons = page->out_cons;
-    if (prod == out_cons)
-       return;
+    if (prod - out_cons >= XENFB_OUT_RING_LEN) {
+        return;
+    }
     xen_rmb();         /* ensure we see ring contents up to prod */
     for (cons = out_cons; cons != prod; cons++) {
        union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);