From e0eff8517cae198fd96106986f7ee8839210c928 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Mon, 24 Mar 2008 15:33:42 -0700 Subject: [PATCH] --- yaml --- r: 90273 b: refs/heads/master c: 2342fd7e146f05edeb13feb03490c13a1bdab2e0 h: refs/heads/master i: 90271: 5e7637d99f5a10dc57d3cf86b921ad8574ef4831 v: v3 --- [refs] | 2 +- trunk/net/ipv4/af_inet.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 83f6fe8b80e3..91bd7e749c1e 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: f145049a06f470d0489f47cb83ff3ccb2a0de622 +refs/heads/master: 2342fd7e146f05edeb13feb03490c13a1bdab2e0 diff --git a/trunk/net/ipv4/af_inet.c b/trunk/net/ipv4/af_inet.c index a9e241cdc5b2..39ddb84b1b78 100644 --- a/trunk/net/ipv4/af_inet.c +++ b/trunk/net/ipv4/af_inet.c @@ -243,6 +243,23 @@ void build_ehash_secret(void) } EXPORT_SYMBOL(build_ehash_secret); +static inline int inet_netns_ok(struct net *net, int protocol) +{ + int hash; + struct net_protocol *ipprot; + + if (net == &init_net) + return 1; + + hash = protocol & (MAX_INET_PROTOS - 1); + ipprot = rcu_dereference(inet_protos[hash]); + + if (ipprot == NULL) + /* raw IP is OK */ + return 1; + return ipprot->netns_ok; +} + /* * Create an inet socket. */ @@ -259,9 +276,6 @@ static int inet_create(struct net *net, struct socket *sock, int protocol) int try_loading_module = 0; int err; - if (net != &init_net) - return -EAFNOSUPPORT; - if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM && !inet_ehash_secret) @@ -320,6 +334,10 @@ static int inet_create(struct net *net, struct socket *sock, int protocol) if (answer->capability > 0 && !capable(answer->capability)) goto out_rcu_unlock; + err = -EAFNOSUPPORT; + if (!inet_netns_ok(net, protocol)) + goto out_rcu_unlock; + sock->ops = answer->ops; answer_prot = answer->prot; answer_no_check = answer->no_check;