pt_chown arbitrary pts access via user namespace
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
glibc (Ubuntu) |
Fix Released
|
Undecided
|
Adam Conrad |
Bug Description
With Ubuntu Wily and earlier, /usr/lib/pt_chown was used to change ownership of slave pts devices in /dev/pts to the same uid holding the master file descriptor for the slave. This is done using the pt_chown SUID binary, which invokes the ptsname function on the master-fd, thus again performing a TIOCGPTN ioctl to get the slave pts number. Using the result from the ioctl, the pathname of the slave pts is constructed and chown invoked on it, see login/programs/
pty = ptsname (PTY_FILENO);
if (pty == NULL)
...
/* Get the group ID of the special `tty' group. */
p = getgrnam (TTY_GROUP);
gid = p ? p->gr_gid : getgid ();
/* Set the owner to the real user ID, and the group to that special
group ID. */
if (chown (pty, getuid (), gid) < 0)
return FAIL_EACCES;
/* Set the permission mode to readable and writable by the owner,
and writable by the group. */
if ((st.st_mode & ACCESSPERMS) != (S_IRUSR|
&& chmod (pty, S_IRUSR|
return FAIL_EACCES;
return 0;
The logic above is severely flawed, when there can be more than one master/slave pair having the same number and thus same name. But this condition can be easily created by creating an user namespace, mounting devpts with the newinstance option, create master and slave pts pairs until the number overlaps with a target pts outside the namespace on the host, where there is interest to gain ownership and then invoke pt_chown.
See http://
# lsb_release -rd
Description: Ubuntu 15.10
Release: 15.10
# apt-cache policy libc-bin
libc-bin:
Installed: 2.21-0ubuntu4
Candidate: 2.21-0ubuntu4
Version table:
*** 2.21-0ubuntu4 0
500 http://
100 /var/lib/
CVE References
Changed in glibc (Ubuntu): | |
status: | New → Confirmed |
Changed in glibc (Ubuntu): | |
assignee: | nobody → Adam Conrad (adconrad) |
Changed in glibc (Ubuntu): | |
status: | Confirmed → Fix Released |
Thanks Halfdog; this is currently under active discussion elsewhere; the solution for Wily and previous releases is far from obvious.
Foundations team, it'd be fantastic to stop shipping the setuid root /usr/lib/pt_chown executable in Xenial.
Thanks