diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2007-10-09 02:24:22 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:49:07 -0400 |
commit | 1b8d7ae42d02e483ad94035cca851e4f7fbecb40 (patch) | |
tree | 81f8cc0ee49ef99cc67dfed3dc7b7ecb510abf8b /net/socket.c | |
parent | 457c4cbc5a3dde259d2a1f15d5f9785290397267 (diff) |
[NET]: Make socket creation namespace safe.
This patch passes in the namespace a new socket should be created in
and has the socket code do the appropriate reference counting. By
virtue of this all socket create methods are touched. In addition
the socket create methods are modified so that they will fail if
you attempt to create a socket in a non-default network namespace.
Failing if we attempt to create a socket outside of the default
network namespace ensures that as we incrementally make the network stack
network namespace aware we will not export functionality that someone
has not audited and made certain is network namespace safe.
Allowing us to partially enable network namespaces before all of the
exotic protocols are supported.
Any protocol layers I have missed will fail to compile because I now
pass an extra parameter into the socket creation code.
[ Integrated AF_IUCV build fixes from Andrew Morton... -DaveM ]
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/net/socket.c b/net/socket.c index b09eb9036a17..a714c6d4e4a1 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -84,6 +84,7 @@ | |||
84 | #include <linux/kmod.h> | 84 | #include <linux/kmod.h> |
85 | #include <linux/audit.h> | 85 | #include <linux/audit.h> |
86 | #include <linux/wireless.h> | 86 | #include <linux/wireless.h> |
87 | #include <linux/nsproxy.h> | ||
87 | 88 | ||
88 | #include <asm/uaccess.h> | 89 | #include <asm/uaccess.h> |
89 | #include <asm/unistd.h> | 90 | #include <asm/unistd.h> |
@@ -1071,7 +1072,7 @@ call_kill: | |||
1071 | return 0; | 1072 | return 0; |
1072 | } | 1073 | } |
1073 | 1074 | ||
1074 | static int __sock_create(int family, int type, int protocol, | 1075 | static int __sock_create(struct net *net, int family, int type, int protocol, |
1075 | struct socket **res, int kern) | 1076 | struct socket **res, int kern) |
1076 | { | 1077 | { |
1077 | int err; | 1078 | int err; |
@@ -1147,7 +1148,7 @@ static int __sock_create(int family, int type, int protocol, | |||
1147 | /* Now protected by module ref count */ | 1148 | /* Now protected by module ref count */ |
1148 | rcu_read_unlock(); | 1149 | rcu_read_unlock(); |
1149 | 1150 | ||
1150 | err = pf->create(sock, protocol); | 1151 | err = pf->create(net, sock, protocol); |
1151 | if (err < 0) | 1152 | if (err < 0) |
1152 | goto out_module_put; | 1153 | goto out_module_put; |
1153 | 1154 | ||
@@ -1186,12 +1187,12 @@ out_release: | |||
1186 | 1187 | ||
1187 | int sock_create(int family, int type, int protocol, struct socket **res) | 1188 | int sock_create(int family, int type, int protocol, struct socket **res) |
1188 | { | 1189 | { |
1189 | return __sock_create(family, type, protocol, res, 0); | 1190 | return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); |
1190 | } | 1191 | } |
1191 | 1192 | ||
1192 | int sock_create_kern(int family, int type, int protocol, struct socket **res) | 1193 | int sock_create_kern(int family, int type, int protocol, struct socket **res) |
1193 | { | 1194 | { |
1194 | return __sock_create(family, type, protocol, res, 1); | 1195 | return __sock_create(&init_net, family, type, protocol, res, 1); |
1195 | } | 1196 | } |
1196 | 1197 | ||
1197 | asmlinkage long sys_socket(int family, int type, int protocol) | 1198 | asmlinkage long sys_socket(int family, int type, int protocol) |