Bug 55678

Summary: XlcConverterList conv_list access are not thread safe
Product: xorg Reporter: Alessandro Pignotti <alexpigna.dev>
Component: Lib/XlibAssignee: Xorg Project Team <xorg-team>
Status: RESOLVED MOVED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium CC: cigydd, jeremyhu, jre.winesim
Version: git   
Hardware: All   
OS: All   
Whiteboard: 2012BRB_Reviewed
i915 platform: i915 features:
Attachments:
Description Flags
A hack to improve the thread safety of the libX11 localization
none
A hack to remove an optimization that is thread unsafe none

Description Alessandro Pignotti 2012-10-05 20:21:11 UTC
In file src/xlibi18n/lcConv.c the following linked list head is defined

static XlcConverterList conv_list = NULL;

Which is then modified by _XlcSetConverter and get_converter in a non thread-safe manner. Inside get_converter the list is reorderder to increase the efficiency of looking up the same element the next time, but this is especially dangerous since a seemingly read-only method is actually modifying the data.

Modifying the list in such thread unsafe manner does case the list to become garbled in some workloads and causes infinite loops when the get_converter is invoked. The solution I suggest is to add a mutex or spinlock around accesses to the linked list, I would it myself but I'm not sure about what is the usual mutex implementation for this project.
Comment 1 Alessandro Pignotti 2012-10-05 22:32:37 UTC
Also the following definitions:

static XlcDatabaseList _db_list = (XlcDatabaseList)NULL;

in file src/xlibi18n/lcDB.c is affected by the similar issues.

It looks like the localization support inside libx11 is generally not thread safe.
Comment 2 Scott Ritchie 2012-10-11 23:47:48 UTC
It should be noted that this is causing a lockup on the Origin game client under Wine, making a good chunk of games unplayable.
Comment 3 Pavel Řezníček 2017-03-30 16:46:12 UTC
Created attachment 130584 [details] [review]
A hack to improve the thread safety of the libX11 localization

Originally posted here: https://bugs.launchpad.net/ubuntu/+source/libx11/+bug/1062534 by Alessandro Pignotti
Comment 4 Pavel Řezníček 2017-03-30 16:48:21 UTC
Created attachment 130585 [details] [review]
A hack to remove an optimization that is thread unsafe

Originally posted here: https://bugs.launchpad.net/ubuntu/+source/libx11/+bug/1062534 by Alessandro Pignotti
Comment 5 Pavel Řezníček 2017-03-30 16:57:35 UTC
Appended two patches from Alessandro Pignotti originally posted on the Ubuntu Bugzilla. They may or may not still be valid.

According to Alessandro's words, "They should be considered hacks to make the problem more clear."

Trying to attract some attention to this bug because I face it on a regular basis playing Lord of the Rings Online on Wine still after 5 years a patch has been proposed.

I'm a bit experienced in programming but only in Pascal and Python so I'm trying to find someone more experienced who could possibly fix it. If nobody responds, maybe I'll try to fix it myself…
Comment 6 GitLab Migration User 2018-08-10 20:10:20 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xorg/lib/libx11/issues/24.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.