From: Kees Cook <keescook@chromium.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH] VFS: add config options to enable link restrictions
Date: Fri, 26 Oct 2012 11:50:21 -0700 [thread overview]
Message-ID: <20121026185021.GA1960@www.outflux.net> (raw)
There are situations where devices running without initrds may need
very early protection from link vulnerabilities, so make these sysctls
configurable at build time, since 561ec64ae67e ("VFS: don't do protected
{sym,hard}links by default") has disabled the protections by default.
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
fs/Kconfig | 39 +++++++++++++++++++++++++++++++++++++++
fs/namei.c | 6 ++++--
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/fs/Kconfig b/fs/Kconfig
index f95ae3a..46ae2dc 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -276,4 +276,43 @@ endif # NETWORK_FILESYSTEMS
source "fs/nls/Kconfig"
source "fs/dlm/Kconfig"
+config PROTECTED_SYMLINKS
+ bool "Protect symlink following in sticky world-writable dirs"
+ default n
+ help
+ Solve the class of ToCToU symlink race vulnerabilities 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.
+
+ See Documentation/sysctl/fs.txt for details.
+
+config PROTECTED_SYMLINKS_SYSCTL
+ int
+ default "1" if PROTECTED_SYMLINKS
+ default "0"
+
+config PROTECTED_HARDLINKS
+ bool "Protect hardlink creation to non-accessible files"
+ default n
+ help
+ Solve the class of ToCToU hardlink race vulnerabilities by
+ permitting hardlinks to be created only when to a regular file
+ that is owned by the user, or is readable and writable by the
+ user. Also blocks users from "pinning" vulnerable setuid/setgid
+ programs from being upgraded by the administrator.
+
+ When PROC_SYSCTL is enabled, this setting can also be controlled
+ via /proc/sys/kernel/protected_hardlinks.
+
+ See Documentation/sysctl/fs.txt for details.
+
+config PROTECTED_HARDLINKS_SYSCTL
+ int
+ default "1" if PROTECTED_HARDLINKS
+ default "0"
+
endmenu
diff --git a/fs/namei.c b/fs/namei.c
index 937f9d5..21854df 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -705,8 +705,10 @@ static inline void put_link(struct nameidata *nd, struct path *link, void *cooki
path_put(link);
}
-int sysctl_protected_symlinks __read_mostly = 0;
-int sysctl_protected_hardlinks __read_mostly = 0;
+int sysctl_protected_symlinks __read_mostly =
+ CONFIG_PROTECTED_SYMLINKS_SYSCTL;
+int sysctl_protected_hardlinks __read_mostly =
+ CONFIG_PROTECTED_HARDLINKS_SYSCTL;
/**
* may_follow_link - Check symlink following for unsafe situations
--
1.7.9.5
--
Kees Cook
Chrome OS Security
next reply other threads:[~2012-10-26 18:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-26 18:50 Kees Cook [this message]
2012-10-26 19:08 ` Al Viro
2012-10-26 19:21 ` Linus Torvalds
2012-10-26 19:46 ` Kees Cook
2012-10-26 20:12 ` Linus Torvalds
2012-10-26 20:23 ` Kees Cook
2012-10-26 20:27 ` Linus Torvalds
2012-10-26 21:41 ` Kees Cook
2012-10-26 21:22 ` Boaz Harrosh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121026185021.GA1960@www.outflux.net \
--to=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome