git.iko.soy/typeable/nixpkgs
on master help sign in
Xorg: apply patch to fix X crashes

(cherry picked from commit dc0fe8ebf40b7724de1ca0b195236854591fdb5f) Signed-off-by: Domen Kožar <domen@dev.si>

commit66214fba8d41967bc1af1a11103968e35d985b66 authorDomen Kožar <domen@dev.si> dateFri 4 Sep 2015, 14:03 (11 years ago) parent8bfacda
2 files changed+65−1
pkgs/servers/x11/xorg/fix_segfault.patch+63 pkgs/servers/x11/xorg/overrides.nix+2−1
pkgs/servers/x11/xorg/fix_segfault.patchnew file+63
@@ -0,0 +1,63 @@
1+From 7cc7ffd25d5e50b54cb942d07d4cb160f20ff9c5 Mon Sep 17 00:00:00 2001
2+From: Martin Peres <martin.peres@linux.intel.com>
3+Date: Fri, 17 Jul 2015 17:21:26 +0300
4+Subject: [PATCH] os: make sure the clientsWritable fd_set is initialized
5+ before use
6+
7+In WaitForSomething(), the fd_set clientsWritable may be used unitialized when
8+the boolean AnyClientsWriteBlocked is set in the WakeupHandler(). This leads to
9+a crash in FlushAllOutput() after x11proto's commit
10+2c94cdb453bc641246cc8b9a876da9799bee1ce7.
11+
12+The problem did not manifest before because both the XFD_SIZE and the maximum
13+number of clients were set to 256. As the connectionTranslation table was
14+initalized for the 256 clients to 0, the test on the index not being 0 was
15+aborting before dereferencing the client #0.
16+
17+As of commit 2c94cdb453bc641246cc8b9a876da9799bee1ce7 in x11proto, the XFD_SIZE
18+got bumped to 512. This lead the OutputPending fd_set to have any fd above 256
19+to be uninitialized which in turns lead to reading an index after the end of
20+the ConnectionTranslation table. This index would then be used to find the
21+client corresponding to the fd marked as pending writes and would also result
22+to an out-of-bound access which would usually be the fatal one.
23+
24+Fix this by zeroing the clientsWritable fd_set at the beginning of
25+WaitForSomething(). In this case, the bottom part of the loop, which would
26+indirectly call FlushAllOutput, will not do any work but the next call to
27+select will result in the execution of the right codepath. This is exactly what
28+we want because we need to know the writable clients before handling them. In
29+the end, it also makes sure that the fds above MaxClient are initialized,
30+preventing the crash in FlushAllOutput().
31+
32+Thanks to everyone involved in tracking this one down!
33+
34+Reported-by: Karol Herbst <freedesktop@karolherbst.de>
35+Reported-by: Tobias Klausmann <tobias.klausmann@mni.thm.de>
36+Signed-off-by: Martin Peres <martin.peres@linux.intel.com>
37+Tested-by: Martin Peres <martin.peres@linux.intel.com>
38+Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91316
39+Cc: Ilia Mirkin <imirkin@alum.mit.edu>
40+Cc: Martin Peres <martin.peres@linux.intel.com>
41+Cc: Olivier Fourdan <ofourdan@redhat.com
42+Cc: Adam Jackson <ajax@redhat.com>
43+Cc: Alan Coopersmith <alan.coopersmith@oracle.com
44+Cc: Chris Wilson <chris@chris-wilson.co.uk>
45+---
46+ os/WaitFor.c | 1 +
47+ 1 file changed, 1 insertion(+)
48+
49+diff --git a/os/WaitFor.c b/os/WaitFor.c
50+index 431f1a6..993c14e 100644
51+--- a/os/WaitFor.c
52++++ b/os/WaitFor.c
53+@@ -158,6 +158,7 @@ WaitForSomething(int *pClientsReady)
54+ Bool someReady = FALSE;
55+
56+ FD_ZERO(&clientsReadable);
57++ FD_ZERO(&clientsWritable);
58+
59+ if (nready)
60+ SmartScheduleStopTimer();
61+--
62+2.4.5
63+
pkgs/servers/x11/xorg/overrides.nix+2−1
@@ -282,7 +282,8 @@ in
282282 inputproto xextproto randrproto renderproto presentproto
283283 dri2proto dri3proto kbproto xineramaproto resourceproto scrnsaverproto videoproto
284284 ];
285− commonPatches = [ ./xorgserver-xkbcomp-path.patch ];
285+ # fix_segfault: https://bugs.freedesktop.org/show_bug.cgi?id=91316
286+ commonPatches = [ ./xorgserver-xkbcomp-path.patch ./fix_segfault.patch ];
286287 # XQuartz requires two compilations: the first to get X / XQuartz,
287288 # and the second to get Xvfb, Xnest, etc.
288289 darwinOtherX = overrideDerivation xorgserver (oldAttrs: {