|
Subject: Postfix local privilege escalation via hardlinked symlinks Newsgroups: gmane.mail.postfix.announce Date: 2008-08-14 12:05:28 GMT (46 weeks, 1 day, 11 hours and 5 minutes ago) Summary: Solaris and Linux file system behavior has changed over time, breaking one of the assumptions in Postfix. See below for a description of the behavior and how it disagrees with standards. Postfix is not affected on systems with standard (POSIX, X/Open) file system behavior, i.e. *BSD, AIX, MacOS, HP-UX, and very old Sun/Linux systems. The fix and workarounds are simple. There are efforts to get the non-standard behavior approved by standards (a function called llink). Today's fix for Solaris, Linux etc. also makes Postfix future-proof for such changes. Wietse 1. Postfix local privilege escalation via hardlinked symlinks ============================================================= Sebastian Krahmer of SuSE has found a privilege escalation problem. On some systems an attacker can hardlink a root-owned symlink to for example /var/mail, and cause Postfix to append mail to existing files that are owned by root or non-root accounts. This can happen on operating systems with specific non-standard behavior. Symlinks (symbolic links) implement aliasing for UNIX pathnames. They were introduced with 4.2BSD UNIX in 1983, and were adopted by other UNIX systems in the course of time. Hardlinks are older and implement the primary mechanism for accessing file system objects. In some UNIX systems, the link(symlink, newpath) operation has changed over time: instead of recursively following the symlink and creating a hardlink to the file thus found, it creates a hardlink to the symlink itself. This behavior disagrees with, for example, the POSIX.1-2001 and X/Open XPG4v2 standards, and is the default on current Solaris, IRIX and Linux systems. On systems with this non-standard behavior, Postfix may be vulnerable depending on how it is configured. Postfix allows a root-owned symlink as a local mail destination, so that mail can be delivered to e.g. /dev/null which is a symlink on Solaris. 2. What configurations are (not) affected ========================================= A configuration is considered affected when an attacker with local access to a system can make Postfix append mail to an existing file of a different user. Appendix A gives a procedure to determine if a system is affected. The following configurations are NOT affected: Postfix on FreeBSD 7.0, OpenBSD 4.3, NetBSD 4.0, MacOS X 10.5, AIX 5.3, HP-UX 11.11, Solaris 1.x, Linux kernel 1.2.13, and other systems with standard hardlink behavior. However, these systems may become affected when they share file systems with hosts where users can create hardlinks to symlinks. Also not affected are the following configurations: a) maildir-style delivery with the Postfix built-in local or virtual delivery agents; b) mail delivery with non-Postfix local or virtual delivery agents; c) mailbox-style delivery with the Postfix built-in virtual delivery agent when virtual mailbox parent directories have no "group" or other write permissions. The following configurations are known to be affected on Linux kernel >= 2.0, Solaris >= 2.0, OpenSolaris 11-2008.5, IRIX 6.5, and other systems where users can create hardlinks to symlinks: a) mailbox-style delivery with the Postfix built-in local delivery agent; b) mailbox-style delivery with the Postfix built-in virtual delivery agent when virtual mailbox parent directories have "group" or other write permissions. 3. Solution =========== If your system is affected, upgrade Postfix, apply the patch in Appendix C, or apply one of the countermeasures in section 4. Updated versions will be made available via http://www.postfix.org/ for Postfix versions 2.3, 2.4, 2.5, and 2.6. Individual vendors will provide updates depending on their support policy. 4. Countermeasures ================== Each of the following countermeasures will prevent privilege escalation through Postfix via hardlinked symlinks: 1) Protect mailbox files (maildir files are not affected). The script in Appendix B makes sure that the system mail spool directory is owned by root, that the sticky bit is turned on, and that each UNIX account has a mailbox file; it also has suggestions for virtual mailbox file deliveries (again, maildir files are not affected). 2) Don't allow non-root users to create hardlinks to objects of other users. This behavior is configurable on some systems. Appendix A: Procedure to find out if a system is affected ========================================================= As mentioned in section 2, not affected are maildir-style delivery with the Postfix built-in local or virtual delivery agents, mail delivery with non-Postfix local or virtual delivery agents, and mailbox-style delivery with the built-in Postfix virtual delivery agent when virtual mailbox parent directories have no "group" or other write permissions. To find out if a system may be affected, execute the following commands as non-root user on a local file system: $ PATH=/bin:/usr/bin:$PATH $ mkdir test $ cd test $ touch src $ ln -s src dst1 $ ln dst1 dst2 $ ls -l For the test to be valid, all commands should complete without error. The system is NOT affected when "ls -l" output shows one symlink (dst1 -> src) and two files (dst2, src) as in example A.1. Example A.1: lrwxr-xr-x 1 user users 3 Mmm dd hh:mm dst1 -> src -rw- |
|
|