Blame SOURCES/0003-dix-integer-overflow-in-GetHosts-CVE-2014-8092-2-4.patch

0fd959
From 014672abf617b4d0585640cdd56ce11cfb51800a Mon Sep 17 00:00:00 2001
0fd959
From: Alan Coopersmith <alan.coopersmith@oracle.com>
0fd959
Date: Mon, 6 Jan 2014 23:30:14 -0800
0fd959
Subject: [PATCH 03/33] dix: integer overflow in GetHosts() [CVE-2014-8092 2/4]
0fd959
0fd959
GetHosts() iterates over all the hosts it has in memory, and copies
0fd959
them to a buffer. The buffer length is calculated by iterating over
0fd959
all the hosts and adding up all of their combined length. There is a
0fd959
potential integer overflow, if there are lots and lots of hosts (with
0fd959
a combined length of > ~4 gig). This should be possible by repeatedly
0fd959
calling ProcChangeHosts() on 64bit machines with enough memory.
0fd959
0fd959
This patch caps the list at 1mb, because multi-megabyte hostname
0fd959
lists for X access control are insane.
0fd959
0fd959
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
0fd959
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
0fd959
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
0fd959
Signed-off-by: Fedora X Ninjas <x@fedoraproject.org>
0fd959
---
0fd959
 os/access.c | 6 ++++++
0fd959
 1 file changed, 6 insertions(+)
0fd959
0fd959
diff --git a/os/access.c b/os/access.c
0fd959
index 6d991b3..dc12348 100644
0fd959
--- a/os/access.c
0fd959
+++ b/os/access.c
0fd959
@@ -1323,6 +1323,10 @@ GetHosts(pointer *data, int *pnHosts, int *pLen, BOOL * pEnabled)
0fd959
     for (host = validhosts; host; host = host->next) {
0fd959
         nHosts++;
0fd959
         n += pad_to_int32(host->len) + sizeof(xHostEntry);
0fd959
+        /* Could check for INT_MAX, but in reality having more than 1mb of
0fd959
+           hostnames in the access list is ridiculous */
0fd959
+        if (n >= 1048576)
0fd959
+            break;
0fd959
     }
0fd959
     if (n) {
0fd959
         *data = ptr = malloc(n);
0fd959
@@ -1331,6 +1335,8 @@ GetHosts(pointer *data, int *pnHosts, int *pLen, BOOL * pEnabled)
0fd959
         }
0fd959
         for (host = validhosts; host; host = host->next) {
0fd959
             len = host->len;
0fd959
+            if ((ptr + sizeof(xHostEntry) + len) > (data + n))
0fd959
+                break;
0fd959
             ((xHostEntry *) ptr)->family = host->family;
0fd959
             ((xHostEntry *) ptr)->length = len;
0fd959
             ptr += sizeof(xHostEntry);
0fd959
-- 
0fd959
1.9.3
0fd959