Skip to content

Commit

Permalink
net: pass kern to net_proto_family create function
Browse files Browse the repository at this point in the history
The generic __sock_create function has a kern argument which allows the
security system to make decisions based on if a socket is being created by
the kernel or by userspace.  This patch passes that flag to the
net_proto_family specific create function, so it can do the same thing.

Signed-off-by: Eric Paris <[email protected]>
Acked-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
eparis authored and davem330 committed Nov 6, 2009
1 parent 13f18aa commit 3f378b6
Show file tree
Hide file tree
Showing 37 changed files with 80 additions and 43 deletions.
2 changes: 1 addition & 1 deletion drivers/isdn/mISDN/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ base_sock_create(struct net *net, struct socket *sock, int protocol)
}

static int
mISDN_sock_create(struct net *net, struct socket *sock, int proto)
mISDN_sock_create(struct net *net, struct socket *sock, int proto, int kern)
{
int err = -EPROTONOSUPPORT;

Expand Down
3 changes: 2 additions & 1 deletion drivers/net/pppox.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)

EXPORT_SYMBOL(pppox_ioctl);

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

Expand Down
3 changes: 2 additions & 1 deletion include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ struct proto_ops {

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

Expand Down
3 changes: 2 additions & 1 deletion net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ static struct proto ddp_proto = {
* Create a socket. Initialise the socket, blank the addresses
* set the state.
*/
static int atalk_create(struct net *net, struct socket *sock, int protocol)
static int atalk_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
int rc = -ESOCKTNOSUPPORT;
Expand Down
3 changes: 2 additions & 1 deletion net/atm/pvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ static const struct proto_ops pvc_proto_ops = {
};


static int pvc_create(struct net *net, struct socket *sock,int protocol)
static int pvc_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
if (net != &init_net)
return -EAFNOSUPPORT;
Expand Down
7 changes: 4 additions & 3 deletions net/atm/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "signaling.h"
#include "addr.h"

static int svc_create(struct net *net, struct socket *sock,int protocol);
static int svc_create(struct net *net, struct socket *sock, int protocol, int kern);

/*
* Note: since all this is still nicely synchronized with the signaling demon,
Expand Down Expand Up @@ -330,7 +330,7 @@ static int svc_accept(struct socket *sock,struct socket *newsock,int flags)

lock_sock(sk);

error = svc_create(sock_net(sk), newsock,0);
error = svc_create(sock_net(sk), newsock, 0, 0);
if (error)
goto out;

Expand Down Expand Up @@ -650,7 +650,8 @@ static const struct proto_ops svc_proto_ops = {
};


static int svc_create(struct net *net, struct socket *sock,int protocol)
static int svc_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
int error;

Expand Down
3 changes: 2 additions & 1 deletion net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ static struct proto ax25_proto = {
.obj_size = sizeof(struct sock),
};

static int ax25_create(struct net *net, struct socket *sock, int protocol)
static int ax25_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
ax25_cb *ax25;
Expand Down
5 changes: 3 additions & 2 deletions net/bluetooth/af_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ int bt_sock_unregister(int proto)
}
EXPORT_SYMBOL(bt_sock_unregister);

static int bt_sock_create(struct net *net, struct socket *sock, int proto)
static int bt_sock_create(struct net *net, struct socket *sock, int proto,
int kern)
{
int err;

Expand All @@ -144,7 +145,7 @@ static int bt_sock_create(struct net *net, 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(net, sock, proto);
err = bt_proto[proto]->create(net, sock, proto, kern);
bt_sock_reclassify_lock(sock, proto);
module_put(bt_proto[proto]->owner);
}
Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/bnep/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ static struct proto bnep_proto = {
.obj_size = sizeof(struct bt_sock)
};

static int bnep_sock_create(struct net *net, struct socket *sock, int protocol)
static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/cmtp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ static struct proto cmtp_proto = {
.obj_size = sizeof(struct bt_sock)
};

static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol)
static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ static struct proto hci_sk_proto = {
.obj_size = sizeof(struct hci_pinfo)
};

static int hci_sock_create(struct net *net, struct socket *sock, int protocol)
static int hci_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/hidp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ static struct proto hidp_proto = {
.obj_size = sizeof(struct bt_sock)
};

static int hidp_sock_create(struct net *net, struct socket *sock, int protocol)
static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int p
return sk;
}

static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol)
static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/rfcomm/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int
return sk;
}

static int rfcomm_sock_create(struct net *net, struct socket *sock, int protocol)
static int rfcomm_sock_create(struct net *net, struct socket *sock,
int protocol, int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int pro
return sk;
}

static int sco_sock_create(struct net *net, struct socket *sock, int protocol)
static int sco_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/can/af_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ static void can_sock_destruct(struct sock *sk)
skb_queue_purge(&sk->sk_receive_queue);
}

static int can_create(struct net *net, struct socket *sock, int protocol)
static int can_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct can_proto *cp;
Expand Down
3 changes: 2 additions & 1 deletion net/decnet/af_decnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ char *dn_addr2asc(__u16 addr, char *buf)



static int dn_create(struct net *net, struct socket *sock, int protocol)
static int dn_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ static struct proto econet_proto = {
* Create an Econet socket
*/

static int econet_create(struct net *net, struct socket *sock, int protocol)
static int econet_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct econet_sock *eo;
Expand Down
2 changes: 1 addition & 1 deletion net/ieee802154/af_ieee802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static const struct proto_ops ieee802154_dgram_ops = {
* set the state.
*/
static int ieee802154_create(struct net *net, struct socket *sock,
int protocol)
int protocol, int kern)
{
struct sock *sk;
int rc;
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ static inline int inet_netns_ok(struct net *net, int protocol)
* Create an inet socket.
*/

static int inet_create(struct net *net, struct socket *sock, int protocol)
static int inet_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct inet_protosw *answer;
Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/af_inet6.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
}

static int inet6_create(struct net *net, struct socket *sock, int protocol)
static int inet6_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct inet_sock *inet;
struct ipv6_pinfo *np;
Expand Down
3 changes: 2 additions & 1 deletion net/ipx/af_ipx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,8 @@ static struct proto ipx_proto = {
.obj_size = sizeof(struct ipx_sock),
};

static int ipx_create(struct net *net, struct socket *sock, int protocol)
static int ipx_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
int rc = -ESOCKTNOSUPPORT;
struct sock *sk;
Expand Down
7 changes: 4 additions & 3 deletions net/irda/af_irda.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

#include <net/irda/af_irda.h>

static int irda_create(struct net *net, struct socket *sock, int protocol);
static int irda_create(struct net *net, struct socket *sock, int protocol, int kern);

static const struct proto_ops irda_stream_ops;
static const struct proto_ops irda_seqpacket_ops;
Expand Down Expand Up @@ -839,7 +839,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)

IRDA_DEBUG(2, "%s()\n", __func__);

err = irda_create(sock_net(sk), newsock, sk->sk_protocol);
err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0);
if (err)
return err;

Expand Down Expand Up @@ -1062,7 +1062,8 @@ static struct proto irda_proto = {
* Create IrDA socket
*
*/
static int irda_create(struct net *net, struct socket *sock, int protocol)
static int irda_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct irda_sock *self;
Expand Down
3 changes: 2 additions & 1 deletion net/iucv/af_iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio)
}

/* Create an IUCV socket */
static int iucv_sock_create(struct net *net, struct socket *sock, int protocol)
static int iucv_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/key/af_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ static struct proto key_proto = {
.obj_size = sizeof(struct pfkey_sock),
};

static int pfkey_create(struct net *net, struct socket *sock, int protocol)
static int pfkey_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
struct sock *sk;
Expand Down
5 changes: 4 additions & 1 deletion net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ static struct proto llc_proto = {

/**
* llc_ui_create - alloc and init a new llc_ui socket
* @net: network namespace (must be default network)
* @sock: Socket to initialize and attach allocated sk to.
* @protocol: Unused.
* @kern: on behalf of kernel or userspace
*
* Allocate and initialize a new llc_ui socket, validate the user wants a
* socket type we have available.
* Returns 0 upon success, negative upon failure.
*/
static int llc_ui_create(struct net *net, struct socket *sock, int protocol)
static int llc_ui_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
int rc = -ESOCKTNOSUPPORT;
Expand Down
3 changes: 2 additions & 1 deletion net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ static int __netlink_create(struct net *net, struct socket *sock,
return 0;
}

static int netlink_create(struct net *net, struct socket *sock, int protocol)
static int netlink_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct module *module = NULL;
struct mutex *cb_mutex;
Expand Down
3 changes: 2 additions & 1 deletion net/netrom/af_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ static struct proto nr_proto = {
.obj_size = sizeof(struct nr_sock),
};

static int nr_create(struct net *net, struct socket *sock, int protocol)
static int nr_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct nr_sock *nr;
Expand Down
3 changes: 2 additions & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,8 @@ static struct proto packet_proto = {
* Create a packet of type SOCK_PACKET.
*/

static int packet_create(struct net *net, struct socket *sock, int protocol)
static int packet_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct packet_sock *po;
Expand Down
3 changes: 2 additions & 1 deletion net/phonet/af_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static inline void phonet_proto_put(struct phonet_protocol *pp)

/* protocol family functions */

static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
static int pn_socket_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct pn_sock *pn;
Expand Down
3 changes: 2 additions & 1 deletion net/rds/af_rds.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
return 0;
}

static int rds_create(struct net *net, struct socket *sock, int protocol)
static int rds_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;

Expand Down
3 changes: 2 additions & 1 deletion net/rose/af_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ static struct proto rose_proto = {
.obj_size = sizeof(struct rose_sock),
};

static int rose_create(struct net *net, struct socket *sock, int protocol)
static int rose_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
struct rose_sock *rose;
Expand Down
3 changes: 2 additions & 1 deletion net/rxrpc/af_rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ static unsigned int rxrpc_poll(struct file *file, struct socket *sock,
/*
* create an RxRPC socket
*/
static int rxrpc_create(struct net *net, struct socket *sock, int protocol)
static int rxrpc_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct rxrpc_sock *rx;
struct sock *sk;
Expand Down
2 changes: 1 addition & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
/* Now protected by module ref count */
rcu_read_unlock();

err = pf->create(net, sock, protocol);
err = pf->create(net, sock, protocol, kern);
if (err < 0)
goto out_module_put;

Expand Down
Loading

0 comments on commit 3f378b6

Please sign in to comment.