CVE-2017-1000367

We discovered a vulnerability in Sudo’s get_process_ttyname() for Linux: this function opens “/proc/[pid]/stat” (man proc) and reads the device number of the tty from field 7 (tty_nr). Unfortunately, these fields are space-separated and field 2 (comm, the filename of the command) can contain spaces (CVE-2017-1000367).

For example, if we execute Sudo through the symlink “./ 1 “, get_process_ttyname() calls sudo_ttyname_dev() to search for the non-existent tty device number “1” in the built-in search_devs[].

Next, sudo_ttyname_dev() calls the function sudo_ttyname_scan() to search for this non-existent tty device number “1” in a breadth-first traversal of “/dev”.

Last, we exploit this function during its traversal of the world-writable “/dev/shm”: through this vulnerability, a local user can pretend that his tty is any character device on the filesystem, and after two race conditions, he can pretend that his tty is any file on the filesystem.

On an SELinux-enabled system, if a user is Sudoer for a command that does not grant him full root privileges, he can overwrite any file on the filesystem (including root-owned files) with his command’s output, because relabel_tty() (in src/selinux.c) calls open(O_RDWR|O_NONBLOCK) on his tty and dup2()s it to the command’s stdin, stdout, and stderr. This allows any Sudoer user to obtain full root privileges.

Red Hat Enterprise Linux 6 (sudo) | |

Red Hat Enterprise Linux 7 (sudo) | |

Red Hat Enterprise Linux Server (v. 5 ELS) (sudo) | |

Oracle Enterprise Linux 6 | |

Oracle Enterprise Linux 7 | |

Oracle Enterprise Linux Server 5 | |

CentOS Linux 6 (sudo) | |

CentOS Linux 7 (sudo) | |

Debian wheezy | |

Debian jessie | |

Debian stretch | |

Debian sid | |

Ubuntu 17.04 | |

Ubuntu 16.10 | |

Ubuntu 16.04 LTS | |

Ubuntu 14.04 LTS | |

SUSE Linux Enterprise Software Development Kit 12-SP2 | |

SUSE Linux Enterprise Server for Raspberry Pi 12-SP2 | |

SUSE Linux Enterprise Server 12-SP2 | |

SUSE Linux Enterprise Desktop 12-SP2 | |

OpenSuse, Slackware, and Gentoo Linux | |

How do I patch sudo on CentOS/RHEL/Scientific/Oracle Linux server? |

Terminal:> sudo yum update

How do I patch sudo on Fedora Linux server?

Terminal:> sudo dnf update

How do I patch sudo on Suse/OpenSUSE Linux server? |

Terminal:> sudo zypper update

How do I patch sudo on Arch Linux server? |

Terminal:> sudo pacman -Syu

How do I patch sudo on Alpine Linux server? |

Terminal:> apk update && apk upgrade

How do I patch sudo on Slackware Linux server? |

upgradepkg sudo-1.8.20p1-i586-1_slack14.2.txz

How do I patch sudo on Gentoo Linux server? |

Terminal:> emerge --sync

Terminal:> emerge --ask --oneshot --verbose ">=app-admin/sudo-1.8.20_p1"