linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] namei: permit linking with CAP_FOWNER in userns
@ 2015-10-10 14:59 Dirk Steinmetz
  2015-10-20 14:09 ` Dirk Steinmetz
  2015-11-03 17:51 ` Kees Cook
  0 siblings, 2 replies; 35+ messages in thread
From: Dirk Steinmetz @ 2015-10-10 14:59 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel, linux-kernel; +Cc: Dirk Steinmetz

Attempting to hardlink to an unsafe file (e.g. a setuid binary) from
within an unprivileged user namespace fails, even if CAP_FOWNER is held
within the namespace. This may cause various failures, such as a gentoo
installation within a lxc container failing to build and install specific
packages.

This change permits hardlinking of files owned by mapped uids, if
CAP_FOWNER is held for that namespace. Furthermore, it improves consistency
by using the existing inode_owner_or_capable(), which is aware of
namespaced capabilities as of 23adbe12ef7d3 ("fs,userns: Change
inode_capable to capable_wrt_inode_uidgid").

Signed-off-by: Dirk Steinmetz <public@rsjtdrjgfuzkfg.com>
---
 fs/namei.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 726d211..29fc6a6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -955,26 +955,23 @@ static bool safe_hardlink_source(struct inode *inode)
  *  - sysctl_protected_hardlinks enabled
  *  - fsuid does not match inode
  *  - hardlink source is unsafe (see safe_hardlink_source() above)
- *  - not CAP_FOWNER
+ *  - not CAP_FOWNER in a namespace with the inode owner uid mapped
  *
  * Returns 0 if successful, -ve on error.
  */
 static int may_linkat(struct path *link)
 {
-	const struct cred *cred;
 	struct inode *inode;
 
 	if (!sysctl_protected_hardlinks)
 		return 0;
 
-	cred = current_cred();
 	inode = link->dentry->d_inode;
 
 	/* Source inode owner (or CAP_FOWNER) can hardlink all they like,
 	 * otherwise, it must be a safe source.
 	 */
-	if (uid_eq(cred->fsuid, inode->i_uid) || safe_hardlink_source(inode) ||
-	    capable(CAP_FOWNER))
+	if (inode_owner_or_capable(inode) || safe_hardlink_source(inode))
 		return 0;
 
 	audit_log_link_denied("linkat", link);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2015-11-20  0:11 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-10 14:59 [PATCH] namei: permit linking with CAP_FOWNER in userns Dirk Steinmetz
2015-10-20 14:09 ` Dirk Steinmetz
2015-10-27 14:33   ` Seth Forshee
2015-10-27 18:08     ` Dirk Steinmetz
2015-10-27 20:28       ` Serge Hallyn
2015-10-28 15:07         ` Dirk Steinmetz
2015-10-28 17:33           ` Serge Hallyn
2015-11-02 15:10             ` Dirk Steinmetz
2015-11-02 18:02               ` Serge Hallyn
2015-11-02 19:57                 ` Andy Lutomirski
2015-11-03  0:39                   ` [RFC] namei: prevent sgid-hardlinks for unmapped gids Dirk Steinmetz
2015-11-03 15:44                     ` Serge Hallyn
2015-11-03 18:20                     ` Kees Cook
2015-11-03 23:21                       ` Dirk Steinmetz
2015-11-03 23:29                         ` Kees Cook
2015-11-04  6:58                           ` Willy Tarreau
2015-11-04 17:59                             ` Andy Lutomirski
2015-11-04 18:15                               ` Willy Tarreau
2015-11-04 18:17                                 ` Andy Lutomirski
2015-11-04 18:28                                   ` Willy Tarreau
2015-11-06 21:59                               ` Kees Cook
2015-11-06 22:30                                 ` Andy Lutomirski
2015-11-07  0:11                                   ` Kees Cook
2015-11-07  0:16                                     ` Kees Cook
2015-11-07  0:48                                       ` Andy Lutomirski
2015-11-07  5:05                                         ` Kees Cook
2015-11-08  2:02                                           ` Theodore Ts'o
2015-11-10 15:08                                             ` Jan Kara
2015-11-19 20:11                                               ` Kees Cook
2015-11-19 21:57                                                 ` Andy Lutomirski
2015-11-19 22:02                                                 ` Dave Chinner
2015-11-20  0:11                                                   ` Kees Cook
2015-11-04 14:46                       ` Serge E. Hallyn
2015-10-27 21:04     ` [PATCH] namei: permit linking with CAP_FOWNER in userns Eric W. Biederman
2015-11-03 17:51 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).