Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b8d7ae4 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller
Browse files

[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: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 457c4cbc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -477,12 +477,12 @@ static struct proto pppoe_sk_proto = {
 * Initialize a new struct sock.
 *
 **********************************************************************/
static int pppoe_create(struct socket *sock)
static int pppoe_create(struct net *net, struct socket *sock)
{
	int error = -ENOMEM;
	struct sock *sk;

	sk = sk_alloc(PF_PPPOX, GFP_KERNEL, &pppoe_sk_proto, 1);
	sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppoe_sk_proto, 1);
	if (!sk)
		goto out;

+2 −2
Original line number Diff line number Diff line
@@ -1411,12 +1411,12 @@ static struct proto pppol2tp_sk_proto = {

/* socket() handler. Initialize a new struct sock.
 */
static int pppol2tp_create(struct socket *sock)
static int pppol2tp_create(struct net *net, struct socket *sock)
{
	int error = -ENOMEM;
	struct sock *sk;

	sk = sk_alloc(PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto, 1);
	sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto, 1);
	if (!sk)
		goto out;

+5 −2
Original line number Diff line number Diff line
@@ -104,10 +104,13 @@ int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)

EXPORT_SYMBOL(pppox_ioctl);

static int pppox_create(struct socket *sock, int protocol)
static int pppox_create(struct net *net, struct socket *sock, int protocol)
{
	int rc = -EPROTOTYPE;

	if (net != &init_net)
		return -EAFNOSUPPORT;

	if (protocol < 0 || protocol > PX_MAX_PROTO)
		goto out;

@@ -123,7 +126,7 @@ static int pppox_create(struct socket *sock, int protocol)
	    !try_module_get(pppox_protos[protocol]->owner))
		goto out;

	rc = pppox_protos[protocol]->create(sock);
	rc = pppox_protos[protocol]->create(net, sock);

	module_put(pppox_protos[protocol]->owner);
out:
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ static inline struct sock *sk_pppox(struct pppox_sock *po)
struct module;

struct pppox_proto {
	int		(*create)(struct socket *sock);
	int		(*create)(struct net *net, struct socket *sock);
	int		(*ioctl)(struct socket *sock, unsigned int cmd,
				 unsigned long arg);
	struct module	*owner;
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

struct poll_table_struct;
struct inode;
struct net;

#define NPROTO		34		/* should be enough for now..	*/

@@ -169,7 +170,7 @@ struct proto_ops {

struct net_proto_family {
	int		family;
	int		(*create)(struct socket *sock, int protocol);
	int		(*create)(struct net *net, struct socket *sock, int protocol);
	struct module	*owner;
};

Loading