[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>
This commit is contained in:
committed by
David S. Miller
parent
457c4cbc5a
commit
1b8d7ae42d
@ -95,10 +95,13 @@ int bt_sock_unregister(int proto)
|
||||
}
|
||||
EXPORT_SYMBOL(bt_sock_unregister);
|
||||
|
||||
static int bt_sock_create(struct socket *sock, int proto)
|
||||
static int bt_sock_create(struct net *net, struct socket *sock, int proto)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (net != &init_net)
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
if (proto < 0 || proto >= BT_MAX_PROTO)
|
||||
return -EINVAL;
|
||||
|
||||
@ -113,7 +116,7 @@ static int bt_sock_create(struct socket *sock, int proto)
|
||||
read_lock(&bt_proto_lock);
|
||||
|
||||
if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
|
||||
err = bt_proto[proto]->create(sock, proto);
|
||||
err = bt_proto[proto]->create(net, sock, proto);
|
||||
module_put(bt_proto[proto]->owner);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ static struct proto bnep_proto = {
|
||||
.obj_size = sizeof(struct bt_sock)
|
||||
};
|
||||
|
||||
static int bnep_sock_create(struct socket *sock, int protocol)
|
||||
static int bnep_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -213,7 +213,7 @@ static int bnep_sock_create(struct socket *sock, int protocol)
|
||||
if (sock->type != SOCK_RAW)
|
||||
return -ESOCKTNOSUPPORT;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &bnep_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &bnep_proto, 1);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -195,7 +195,7 @@ static struct proto cmtp_proto = {
|
||||
.obj_size = sizeof(struct bt_sock)
|
||||
};
|
||||
|
||||
static int cmtp_sock_create(struct socket *sock, int protocol)
|
||||
static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -204,7 +204,7 @@ static int cmtp_sock_create(struct socket *sock, int protocol)
|
||||
if (sock->type != SOCK_RAW)
|
||||
return -ESOCKTNOSUPPORT;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &cmtp_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &cmtp_proto, 1);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -634,7 +634,7 @@ static struct proto hci_sk_proto = {
|
||||
.obj_size = sizeof(struct hci_pinfo)
|
||||
};
|
||||
|
||||
static int hci_sock_create(struct socket *sock, int protocol)
|
||||
static int hci_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -645,7 +645,7 @@ static int hci_sock_create(struct socket *sock, int protocol)
|
||||
|
||||
sock->ops = &hci_sock_ops;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &hci_sk_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &hci_sk_proto, 1);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -246,7 +246,7 @@ static struct proto hidp_proto = {
|
||||
.obj_size = sizeof(struct bt_sock)
|
||||
};
|
||||
|
||||
static int hidp_sock_create(struct socket *sock, int protocol)
|
||||
static int hidp_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -255,7 +255,7 @@ static int hidp_sock_create(struct socket *sock, int protocol)
|
||||
if (sock->type != SOCK_RAW)
|
||||
return -ESOCKTNOSUPPORT;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &hidp_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &hidp_proto, 1);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -518,11 +518,11 @@ static struct proto l2cap_proto = {
|
||||
.obj_size = sizeof(struct l2cap_pinfo)
|
||||
};
|
||||
|
||||
static struct sock *l2cap_sock_alloc(struct socket *sock, int proto, gfp_t prio)
|
||||
static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, prio, &l2cap_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto, 1);
|
||||
if (!sk)
|
||||
return NULL;
|
||||
|
||||
@ -543,7 +543,7 @@ static struct sock *l2cap_sock_alloc(struct socket *sock, int proto, gfp_t prio)
|
||||
return sk;
|
||||
}
|
||||
|
||||
static int l2cap_sock_create(struct socket *sock, int protocol)
|
||||
static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -560,7 +560,7 @@ static int l2cap_sock_create(struct socket *sock, int protocol)
|
||||
|
||||
sock->ops = &l2cap_sock_ops;
|
||||
|
||||
sk = l2cap_sock_alloc(sock, protocol, GFP_ATOMIC);
|
||||
sk = l2cap_sock_alloc(net, sock, protocol, GFP_ATOMIC);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -1425,7 +1425,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
|
||||
goto response;
|
||||
}
|
||||
|
||||
sk = l2cap_sock_alloc(NULL, BTPROTO_L2CAP, GFP_ATOMIC);
|
||||
sk = l2cap_sock_alloc(parent->sk_net, NULL, BTPROTO_L2CAP, GFP_ATOMIC);
|
||||
if (!sk)
|
||||
goto response;
|
||||
|
||||
|
@ -282,12 +282,12 @@ static struct proto rfcomm_proto = {
|
||||
.obj_size = sizeof(struct rfcomm_pinfo)
|
||||
};
|
||||
|
||||
static struct sock *rfcomm_sock_alloc(struct socket *sock, int proto, gfp_t prio)
|
||||
static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
|
||||
{
|
||||
struct rfcomm_dlc *d;
|
||||
struct sock *sk;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, prio, &rfcomm_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, prio, &rfcomm_proto, 1);
|
||||
if (!sk)
|
||||
return NULL;
|
||||
|
||||
@ -323,7 +323,7 @@ static struct sock *rfcomm_sock_alloc(struct socket *sock, int proto, gfp_t prio
|
||||
return sk;
|
||||
}
|
||||
|
||||
static int rfcomm_sock_create(struct socket *sock, int protocol)
|
||||
static int rfcomm_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -336,7 +336,7 @@ static int rfcomm_sock_create(struct socket *sock, int protocol)
|
||||
|
||||
sock->ops = &rfcomm_sock_ops;
|
||||
|
||||
sk = rfcomm_sock_alloc(sock, protocol, GFP_ATOMIC);
|
||||
sk = rfcomm_sock_alloc(net, sock, protocol, GFP_ATOMIC);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -868,7 +868,7 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc *
|
||||
goto done;
|
||||
}
|
||||
|
||||
sk = rfcomm_sock_alloc(NULL, BTPROTO_RFCOMM, GFP_ATOMIC);
|
||||
sk = rfcomm_sock_alloc(parent->sk_net, NULL, BTPROTO_RFCOMM, GFP_ATOMIC);
|
||||
if (!sk)
|
||||
goto done;
|
||||
|
||||
|
@ -414,11 +414,11 @@ static struct proto sco_proto = {
|
||||
.obj_size = sizeof(struct sco_pinfo)
|
||||
};
|
||||
|
||||
static struct sock *sco_sock_alloc(struct socket *sock, int proto, gfp_t prio)
|
||||
static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
sk = sk_alloc(PF_BLUETOOTH, prio, &sco_proto, 1);
|
||||
sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto, 1);
|
||||
if (!sk)
|
||||
return NULL;
|
||||
|
||||
@ -439,7 +439,7 @@ static struct sock *sco_sock_alloc(struct socket *sock, int proto, gfp_t prio)
|
||||
return sk;
|
||||
}
|
||||
|
||||
static int sco_sock_create(struct socket *sock, int protocol)
|
||||
static int sco_sock_create(struct net *net, struct socket *sock, int protocol)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
@ -452,7 +452,7 @@ static int sco_sock_create(struct socket *sock, int protocol)
|
||||
|
||||
sock->ops = &sco_sock_ops;
|
||||
|
||||
sk = sco_sock_alloc(sock, protocol, GFP_ATOMIC);
|
||||
sk = sco_sock_alloc(net, sock, protocol, GFP_ATOMIC);
|
||||
if (!sk)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -807,7 +807,7 @@ static void sco_conn_ready(struct sco_conn *conn)
|
||||
|
||||
bh_lock_sock(parent);
|
||||
|
||||
sk = sco_sock_alloc(NULL, BTPROTO_SCO, GFP_ATOMIC);
|
||||
sk = sco_sock_alloc(parent->sk_net, NULL, BTPROTO_SCO, GFP_ATOMIC);
|
||||
if (!sk) {
|
||||
bh_unlock_sock(parent);
|
||||
goto done;
|
||||
|
Reference in New Issue
Block a user