[NET]: Make socket creation namespace safe.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / packet / af_packet.c
index 1322d62b5d97224d74586d5eb92df887a383e7cb..766b5faaed21aa88de5d0a675a5186505276e7c2 100644 (file)
@@ -61,6 +61,7 @@
 #include <linux/wireless.h>
 #include <linux/kernel.h>
 #include <linux/kmod.h>
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
@@ -640,11 +641,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
        h->tp_snaplen = snaplen;
        h->tp_mac = macoff;
        h->tp_net = netoff;
-       if (skb->tstamp.tv64 == 0) {
-               __net_timestamp(skb);
-               sock_enable_timestamp(sk);
-       }
-       tv = ktime_to_timeval(skb->tstamp);
+       if (skb->tstamp.tv64)
+               tv = ktime_to_timeval(skb->tstamp);
+       else
+               do_gettimeofday(&tv);
        h->tp_sec = tv.tv_sec;
        h->tp_usec = tv.tv_usec;
 
@@ -977,13 +977,16 @@ static struct proto packet_proto = {
  *     Create a packet of type SOCK_PACKET.
  */
 
-static int packet_create(struct socket *sock, int protocol)
+static int packet_create(struct net *net, struct socket *sock, int protocol)
 {
        struct sock *sk;
        struct packet_sock *po;
        __be16 proto = (__force __be16)protocol; /* weird, but documented */
        int err;
 
+       if (net != &init_net)
+               return -EAFNOSUPPORT;
+
        if (!capable(CAP_NET_RAW))
                return -EPERM;
        if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
@@ -993,7 +996,7 @@ static int packet_create(struct socket *sock, int protocol)
        sock->state = SS_UNCONNECTED;
 
        err = -ENOBUFS;
-       sk = sk_alloc(PF_PACKET, GFP_KERNEL, &packet_proto, 1);
+       sk = sk_alloc(net, PF_PACKET, GFP_KERNEL, &packet_proto, 1);
        if (sk == NULL)
                goto out;
 
@@ -1952,7 +1955,7 @@ static const struct file_operations packet_seq_fops = {
 
 static void __exit packet_exit(void)
 {
-       proc_net_remove("packet");
+       proc_net_remove(&init_net, "packet");
        unregister_netdevice_notifier(&packet_netdev_notifier);
        sock_unregister(PF_PACKET);
        proto_unregister(&packet_proto);
@@ -1967,7 +1970,7 @@ static int __init packet_init(void)
 
        sock_register(&packet_family_ops);
        register_netdevice_notifier(&packet_netdev_notifier);
-       proc_net_fops_create("packet", 0, &packet_seq_fops);
+       proc_net_fops_create(&init_net, "packet", 0, &packet_seq_fops);
 out:
        return rc;
 }