summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2020-11-07 22:22:47 -0800
committerKeith Packard <keithp@keithp.com>2020-11-15 10:09:16 -0800
commit30ccef3a48029bf4fc31d4abda2d2778d0ad6277 (patch)
tree728256e75ad588f2b5a7deb64069b4f7d0760092 /include
parentc9c4d6efbf92ab51695e2e740319503221d68eed (diff)
Avoid recursing through _XError due to sequence adjustment
This patch is based on research done by Dmitry Osipenko to uncover the cause of a large class of Xlib lockups. _XError must unlock and re-lock the display around the call to the user error handler function. When re-locking the display, two functions are called to ensure that the display is ready to generate a request: _XIDHandler(dpy); _XSeqSyncFunction(dpy); The first ensures that there is at least one XID available to use (possibly calling _xcb_generate_id to do so). The second makes sure a reply is received at least every 65535 requests to keep sequence numbers in sync (possibly generating a GetInputFocus request and synchronously awaiting the reply). If the second of these does generate a GetInputFocus request and wait for the reply, then a pending error will cause recursion into _XError, which deadlocks the display. One seemingly easy fix is to have _XError avoid those calls by invoking InternalLockDisplay instead of LockDisplay. That function does everything that LockDisplay does *except* call those final two functions which may end up receiving an error. However, that doesn't protect the system from applications which call some legal Xlib function from within their error handler. Any Xlib function which cannot generate protocol or wait for events is valid, including many which invoke LockDisplay. What we need to do is make LockDisplay skip these two function calls precisely when it is called from within the _XError context for the same display. This patch accomplishes this by creating a list of threads in the display which are in _XError, and then having LockDisplay check the current thread against those list elements. Inspired-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Keith Packard <keithp@keithp.com> Tested-by: Dmitry Osipenko <digetx@gmail.com> Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/X11/Xlibint.h3
1 files changed, 1 insertions, 2 deletions
diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
index 8b43d3b7..abcc59ac 100644
--- a/include/X11/Xlibint.h
+++ b/include/X11/Xlibint.h
@@ -203,8 +203,7 @@ struct _XDisplay
unsigned long request_upper32bit;
#endif
- /* avoid recursion on requests sequence number synchronization */
- Bool req_seq_syncing; /* requests syncing is in-progress */
+ struct _XErrorThreadInfo *error_threads;
XIOErrorExitHandler exit_handler;
void *exit_handler_data;