1 commit 50c167164700e8ead9b7ccf9f9eafc7541baac75
2 Author: Martin Peres <martin.peres@linux.intel.com>
3 Date: Mon Jul 20 10:37:30 2015 +0300
5 os: make sure the clientsWritable fd_set is initialized before use
7 In WaitForSomething(), the fd_set clientsWritable may be used
8 unitialized when the boolean AnyClientsWriteBlocked is set in the
9 WakeupHandler(). This leads to a crash in FlushAllOutput() after
10 x11proto's commit 2c94cdb453bc641246cc8b9a876da9799bee1ce7.
12 The problem did not manifest before because both the XFD_SIZE and the
13 maximum number of clients were set to 256. As the connectionTranslation
14 table was initalized for the 256 clients to 0, the test on the index not
15 being 0 was aborting before dereferencing the client #0.
17 As of commit 2c94cdb453bc641246cc8b9a876da9799bee1ce7 in x11proto, the
18 XFD_SIZE got bumped to 512. This lead the OutputPending fd_set to have
19 any fd above 256 to be uninitialized which in turns lead to reading an
20 index after the end of the ConnectionTranslation table. This index would
21 then be used to find the client corresponding to the fd marked as
22 pending writes and would also result to an out-of-bound access which
23 would usually be the fatal one.
25 Fix this by zeroing the clientsWritable fd_set at the beginning of
26 WaitForSomething(). In this case, the bottom part of the loop, which
27 would indirectly call FlushAllOutput, will not do any work but the next
28 call to select will result in the execution of the right codepath. This
29 is exactly what we want because we need to know the writable clients
30 before handling them. In the end, it also makes sure that the fds above
31 MaxClient are initialized, preventing the crash in FlushAllOutput().
33 Thanks to everyone involved in tracking this one down!
35 Reported-by: Karol Herbst <freedesktop@karolherbst.de>
36 Reported-by: Tobias Klausmann <tobias.klausmann@mni.thm.de>
37 Signed-off-by: Martin Peres <martin.peres@linux.intel.com>
38 Tested-by: Tobias Klausmann <tobias.klausmann@mni.thm.de>
39 Tested-by: Martin Peres <martin.peres@linux.intel.com>
40 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91316
41 Cc: Ilia Mirkin <imirkin@alum.mit.edu>
42 Cc: Olivier Fourdan <ofourdan@redhat.com
43 Cc: Adam Jackson <ajax@redhat.com>
44 Cc: Alan Coopersmith <alan.coopersmith@oracle.com
45 Cc: Chris Wilson <chris@chris-wilson.co.uk>
46 Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
48 diff --git a/os/WaitFor.c b/os/WaitFor.c
49 index 431f1a6..993c14e 100644
52 @@ -158,6 +158,7 @@ WaitForSomething(int *pClientsReady)
53 Bool someReady = FALSE;
55 FD_ZERO(&clientsReadable);
56 + FD_ZERO(&clientsWritable);
59 SmartScheduleStopTimer();