fs: symlink restrictions on sticky directories
Subsystems (3)
PATCH 2/6 fs: symlink restrictions on sticky directories
From: Kees Cook <[email protected]>
Subject: fs: symlink restrictions on sticky directories
A longstanding class of security issues is the symlink-based time-of-check-time-of-use race, most commonly seen in world-writable directories like /tmp. The common method of exploitation of this flaw is to cross privilege boundaries when following a given symlink (i.e. a root process follows a symlink belonging to another user). For a likely incomplete list of hundreds of examples across the years, please see:
http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=/tmp
The solution is to permit symlinks to only be followed when outside a sticky world-writable directory, or when the uid of the symlink and follower match, or when the directory owner matches the symlink's owner.
Some pointers to the history of earlier discussion that I could find:
1996 Aug, Zygo Blaxell
http://marc.info/?l=bugtraq&m=87602167419830&w=2
1996 Oct, Andrew Tridgell
http://lkml.indiana.edu/hypermail/linux/kernel/9610.2/0086.html
1997 Dec, Albert D Cahalan
http://lkml.org/lkml/1997/12/16/4
2005 Feb, Lorenzo Hernández García-Hierro
http://lkml.indiana.edu/hypermail/linux/kernel/0502.0/1896.html
2010 May, Kees Cook
https://lkml.org/lkml/2010/5/30/144
Past objections and rebuttals could be summarized as:
- Violates POSIX.
- POSIX didn't consider this situation and it's not useful to follow a broken specification at the cost of security.
- Might break unknown applications that use this feature.
- Applications that break because of the change are easy to spot and fix. Applications that are vulnerable to symlink ToCToU by not having the change aren't. Additionally, no applications have yet been found that rely on this behavior.
- Applications should just use mkstemp() or O_CREATE|O_EXCL.
- True, but applications are not perfect, and new software is written all the time that makes these mistakes; blocking this flaw at the kernel is a single solution to the entire class of vulnerability.
- This should live in the core VFS.
- This should live in an LSM. (https://lkml.org/lkml/2010/5/31/135)
- This should live in an LSM.
- This should live in the core VFS. (https://lkml.org/lkml/2010/8/2/188)
This patch is based on the patch in Openwall and grsecurity, along with suggestions from Al Viro. I have added a sysctl to enable the protected behavior, documentation, and an audit notification.
---
Documentation/sysctl/fs.txt | 21 +++++++ fs/Kconfig | 34 ++++++++++++ fs/namei.c | 91 +++++++++++++++++++++++++++++++--- include/linux/fs.h | 1 kernel/sysctl.c | 11 ++++ 5 files changed, 152 insertions(+), 6 deletions(-)
Documentation/sysctl/fs.txt renamed from Documentation/sysctl/fs.txt~fs-symlink-restrictions-on-sticky-directories +21 -0
@@ -32,6 +32,7 @@ Currently, these files are in /proc/sys/ - nr_open - overflowuid - overflowgid +- protected_symlinks - suid_dumpable - super-max - super-nr
@@ -157,6 +158,26 @@ The default is 65534. ============================================================== +protected_symlinks: + +A long-standing class of security issues is the symlink-based +time-of-check-time-of-use race, most commonly seen in world-writable +directories like /tmp. The common method of exploitation of this flaw +is to cross privilege boundaries when following a given symlink (i.e. a +root process follows a symlink belonging to another user). For a likely +incomplete list of hundreds of examples across the years, please see: +http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=/tmp + +When set to "0", symlink following behavior is unrestricted. + +When set to "1" symlinks are permitted to be followed only when outside +a sticky world-writable directory, or when the uid of the symlink and +follower match, or when the directory owner matches the symlink's owner. + +This protection is based on the restrictions in Openwall and grsecurity. + +============================================================== + suid_dumpable: This value can be used to query and set the core dump mode for setuid
fs/Kconfig renamed from fs/Kconfig~fs-symlink-restrictions-on-sticky-directories +34 -0
@@ -276,4 +276,38 @@ endif # NETWORK_FILESYSTEMS source "fs/nls/Kconfig" source "fs/dlm/Kconfig" +config PROTECTED_SYMLINKS + bool "Evaluate vulnerable symlink conditions" + default y + help + A long-standing class of security issues is the symlink-based + time-of-check-time-of-use race, most commonly seen in + world-writable directories like /tmp. The common method of + exploitation of this flaw is to cross privilege boundaries + when following a given symlink (i.e. a root process follows + a malicious symlink belonging to another user). + + Enabling this adds the logic to examine these dangerous symlink + conditions. Whether or not the dangerous symlink situations are + allowed is controlled by PROTECTED_SYMLINKS_ENABLED. + +config PROTECTED_SYMLINKS_ENABLED + depends on PROTECTED_SYMLINKS + bool "Disallow symlink following in sticky world-writable dirs" + default y + help + Solve ToCToU symlink race vulnerablities by permitting symlinks + to be followed only when outside a sticky world-writable directory, + or when the uid of the symlink and follower match, or when the + directory and symlink owners match. + + When PROC_SYSCTL is enabled, this setting can also be controlled + via /proc/sys/kernel/protected_symlinks. + +config PROTECTED_SYMLINKS_ENABLED_SYSCTL + depends on PROTECTED_SYMLINKS + int + default "1" if PROTECTED_SYMLINKS_ENABLED + default "0" + endmenu
fs/namei.c renamed from fs/namei.c~fs-symlink-restrictions-on-sticky-directories +85 -6
123 lines not on this page · raw message
include/linux/fs.h renamed from include/linux/fs.h~fs-symlink-restrictions-on-sticky-directories +1 -0
@@ -428,6 +428,7 @@ extern unsigned long get_max_files(void)extern int sysctl_nr_open;extern struct inodes_stat_t inodes_stat;extern int leases_enable, lease_break_time; +extern int sysctl_protected_symlinks;struct buffer_head ; typedef int (get_block_t)(struct inode *inode, sector_t iblock,
kernel/sysctl.c renamed from kernel/sysctl.c~fs-symlink-restrictions-on-sticky-directories +11 -0
@@ -1504,6 +1504,17 @@ static struct ctl_table fs_table[] = { },#endif #endif +#ifdef CONFIG_PROTECTED_SYMLINKS + { + .procname = "protected_symlinks", + .data = &sysctl_protected_symlinks, + .maxlen = sizeof(int), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, +#endif { .procname = "suid_dumpable", .data = &suid_dumpable,
_
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html