[PATCH 8/8] af_unix: Allow connecting to sockets in other network namespaces.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric W. Biederman
Date: Sunday, June 13, 2010 - 6:35 am

Remove the restriction that only allows connecting to a unix domain
socket identified by unix path that is in the same network namespace.

Crossing network namespaces is always tricky and we did not support
this at first, because of a strict policy of don't mix the namespaces.
Later after Pavel proposed this we did not support this because no one
had performed the audit to make certain using unix domain sockets
across namespaces is safe.

What fundamentally makes connecting to af_unix sockets in other
namespaces is safe is that you have to have the proper permissions on
the unix domain socket inode that lives in the filesystem.  If you
want strict isolation you just don't create inodes where unfriendlys
can get at them, or with permissions that allow unfriendlys to open
them.  All nicely handled for us by the mount namespace and other
standard file system facilities.

I looked through unix domain sockets and they are a very controlled
environment so none of the work that goes on in dev_forward_skb to
make crossing namespaces safe appears needed, we are not loosing
controll of the skb and so do not need to set up the skb to look like
it is comming in fresh from the outside world.  Further the fields in
struct unix_skb_parms should not have any problems crossing network
namespaces.

Now that we handle SCM_CREDENTIALS in a way that gives useable values
across namespaces.  There does not appear to be any operational
problems with encouraging the use of unix domain sockets across
containers either.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 net/unix/af_unix.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 78d412a..4aaff40 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -282,7 +282,7 @@ static inline struct sock *unix_find_socket_byname(struct net *net,
 	return s;
 }
 
-static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
+static struct sock *unix_find_socket_byinode(struct inode *i)
 {
 	struct sock *s;
 	struct hlist_node *node;
@@ -292,9 +292,6 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
 		    &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
 		struct dentry *dentry = unix_sk(s)->dentry;
 
-		if (!net_eq(sock_net(s), net))
-			continue;
-
 		if (dentry && dentry->d_inode == i) {
 			sock_hold(s);
 			goto found;
@@ -757,7 +754,7 @@ static struct sock *unix_find_other(struct net *net,
 		err = -ECONNREFUSED;
 		if (!S_ISSOCK(inode->i_mode))
 			goto put_fail;
-		u = unix_find_socket_byinode(net, inode);
+		u = unix_find_socket_byinode(inode);
 		if (!u)
 			goto put_fail;
 
-- 
1.6.5.2.143.g8cc62

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/8] Support unix domain sockets across namespaces, Eric W. Biederman, (Sun Jun 13, 6:25 am)
[PATCH 1/8] scm: Reorder scm_cookie., Eric W. Biederman, (Sun Jun 13, 6:27 am)
[PATCH 2/8] user_ns: Introduce user_nsmap_uid and user_ns_ ..., Eric W. Biederman, (Sun Jun 13, 6:28 am)
[PATCH 3/8] sock: Introduce cred_to_ucred, Eric W. Biederman, (Sun Jun 13, 6:28 am)
[PATCH 4/8] af_unix: Allow SO_PEERCRED to work across name ..., Eric W. Biederman, (Sun Jun 13, 6:30 am)
[PATCH 5/8] af_netlink: Add needed scm_destroy after scm_send., Eric W. Biederman, (Sun Jun 13, 6:31 am)
[PATCH 6/8] scm: Capture the full credentials of the scm s ..., Eric W. Biederman, (Sun Jun 13, 6:32 am)
[PATCH 7/8] af_unix: Allow credentials to work across user ..., Eric W. Biederman, (Sun Jun 13, 6:34 am)
[PATCH 8/8] af_unix: Allow connecting to sockets in other ..., Eric W. Biederman, (Sun Jun 13, 6:35 am)
Re: [PATCH 1/8] scm: Reorder scm_cookie., Pavel Emelyanov, (Tue Jun 15, 1:00 am)
Re: [PATCH 3/8] sock: Introduce cred_to_ucred, Pavel Emelyanov, (Tue Jun 15, 1:03 am)
Re: [PATCH 6/8] scm: Capture the full credentials of the s ..., Eric W. Biederman, (Tue Jun 15, 2:53 am)
Re: [PATCH 6/8] scm: Capture the full credentials of the s ..., Eric W. Biederman, (Tue Jun 15, 3:08 pm)
Re: [PATCH 2/8] user_ns: Introduce user_nsmap_uid and user ..., Eric W. Biederman, (Tue Jun 15, 3:37 pm)
Re: [PATCH 0/8] Support unix domain sockets across namespaces, Eric W. Biederman, (Wed Jun 16, 4:32 pm)