-
Notifications
You must be signed in to change notification settings - Fork 197
xf86pciBus: replace on thread-safe strtok_r in xf86ParsePciBusString() #1415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Thread A calls xf86ParsePciBusString("PCI:1@0:2:3 "). Execution of strtok_r (in the patched version) or strtok (in the vulnerable version) is suspended after the first call, when the internal pointer is set to the rest of the string ":2:3".
- Thread B (the attacker's thread) calls another function in the X server that also uses strtok (for example, to parse another configuration string). This call overwrites the internal static state of strtok.
- Thread A resumes and calls strtok(NULL, ":") again. Instead of getting the token "2" from the source string, it will receive data from the string processed by Thread B, or NULL, which will lead to incorrect BusID parsing, potential failure, or other unpredictable behavior.
Applying patch with strtok_r completely eliminates this category of vulnerabilities in multithreaded scenarios.
| s = Xstrdup(id); | ||
| p = strtok(s, ":"); | ||
| s = last = Xstrdup(id); | ||
| p = strtok_r(last, ":", &last); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason to use last for both the first and the last argument?
I thought the typical usage would be something like
char *last;
p = strtok_r(s, ":", &last);
|
@metux, in XOrg was created SECURITY.md https://gitlab.freedesktop.org/xorg/xserver/-/commit/a5047d4a6576630d0e15b8f145a44ff6ebe55369 XLibre as a separate fork, would you like to consider creating an isolated environment from the drivers as well? It is possible that someone will write vendor new drivers for the x server in the future, as well as protection against malicious xf86 drivers like viruses. I can help you create a more secure runtime environment in X process and send PRs.
|
|
@metux, As Alan said in SECURITY.md, the Xorg project fully trusts vendors' code and custom modules and eliminates possible errors when writing them that could exploit xorg server vulnerabilities. |
|
@GermanAizek I agree with Alanc here. We want code from modules to be just as fast as code in the X server. You can prevent modules doing stuff like However, you can't prevent stuff like On a properly configured system, X server modules can't be installed without privileges, so this isn't a security vulnerability. If you think I'm wrong here, try patching a module to create a file somewhere on your system where the X server has enough privileges to do so (do it in driver PreInit or something). |

Related to issue: #1398
Applying patch with strtok_r completely eliminates this category of vulnerabilities in multithreaded scenarios.