An incorrect permission check for -modulepath and -logfile options when starting Xorg X server allows unprivileged users with the ability to log in to the system via physical console to escalate their privileges and run arbitrary code under root privileges.
The X.org X11 server has a vulnerability that allows local users to escalate to
full root privileges. The /usr/bin/Xorg setuid binary shipped in the
xorg-x11-server-Xorg package allows for arbitrary file creation with certain
parameters, allowing attackers with low privilege access to overwrite system
files and subsequently execute arbitrary code.
Name: Narendra Shinde
This flaw was introduced in the upstream xserver version 1.19.0 via the following commit:
Prior to that commit, X server command line options -logfile and -modulepath could only be used when X server is started by the root user. The above commit changed checking of these options to use the same code that was previously used for -config and -configdir options, which additionally allows arguments that are relative paths. However, accepting relative paths for -logfile and -modulepath is not safe.
As 1.19.0 is the first affected version, Red Hat Enterprise Linux 7 is only affected as of the erratum RHBA-2017:1905, which was released as part of Red Hat Enterprise Linux 7.4, which rebased xorg-x11-server component from version 1.17.2 to version 1.19.3. The versions of xorg-x11-server as shipped with Red Hat Enterprise Linux 7.3 and earlier are not affected. Therefore, for Red Hat Enterprise Linux 7.4 and later, this issue can be mitigated by downgrading to version 1.17.2.
The versions of xorg-x11-server as shipped with Red Hat Enterprise Linux 6 and earlier were never updated to version 1.19.0 or later, and hence are not affected by this issue.
Note that the default PAM configuration for the xserver in Red Hat Enterprise Linux only allows users with physical access to the console to start Xorg server. This restriction prevents exploitation of this flaw over remote connections, such as over SSH connection.
> Note that the default PAM configuration for the xserver in Red Hat
> Enterprise Linux only allows users with physical access to the console
> to start Xorg server. This >restriction prevents exploitation of this
> flaw over remote connections, such as over SSH connection.
In my testing environment, if user is logged into console, s/he can exploit this issue remotely using SSH too. Could you please check ?
[Dev@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Wed Mar 21 18:14:51 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux
[Dev@localhost ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
[Dev@localhost ~]$ cd /etc
[Dev@localhost etc]$ Xorg -logfile crafted :1
X.Org X Server 1.19.5
Release Date: 2017-10-12
X Protocol Version 11, Revision 0
Build Operating System: 2.6.32-696.18.7.el6.x86_64
Current Operating System: Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Wed Mar 21 18:14:51 EDT 2018 x86_64
Kernel command line: BOOT_IMAGE=/vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet LANG=en_US.UTF-8
Build Date: 13 February 2018 02:39:52PM
Build ID: xorg-x11-server 1.19.5-5.el7
Current version of pixman: 0.34.0
Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(++) Log file: "crafted", Time: Sun Oct 14 21:22:11 2018
(==) Using config directory: "/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
^Cerror setting MTRR (base = 0x00000000e0000000, size = 0x01700000, type = 1) Invalid argument (22)
(II) Server terminated successfully (0). Closing log file.
[Dev@localhost etc]$ ^C
[Dev@localhost etc]$ ^C
[Dev@localhost etc]$ ls -la crafted
-rw-r--r--. 1 root Dev 53902 Oct 14 21:22 crafted
(In reply to Narendra from comment #10)
> In my testing environment, if user is logged into console, s/he can exploit
> this issue remotely using SSH too. Could you please check ?
Right, that's how pam_console works. The point is that attacker needs an open console session to run Xorg, even though it may be associated with a different terminal. If attacker does not have console access to the target system, this PAM configuration prevents them from running Xorg there. Only having remote SSH access is not enough.
Created xorg-x11-server tracking bugs for this issue:
Affects: fedora-all [bug 1643131]
Blog post from the original reporter:
This issue did not affect the versions of xorg-x11-server as shipped with Red Hat Enterprise Linux 5 and 6, as well as Red Hat Enterprise Linux 7 prior to 7.4, as they did not allow the use of vulnerable command line options when running with elevated privileges.
The default X server configuration in Red Hat Enterprise Linux only allows users logged in on the system's physical console to run Xorg X server. Therefore, users which only have remote access to the the system (for example using SSH) can not exploit this flaw.
This issue has been addressed in the following products:
Red Hat Enterprise Linux 7
Via RHSA-2018:3410 https://access.redhat.com/errata/RHSA-2018:3410
Another write up form the original reporter describing exploitation using the -modulepath option: