net: pass kern to net_proto_family create function
[firefly-linux-kernel-4.4.55.git] / net / ipv6 / af_inet6.c
index b6d05881867399781924080ffeee5587d97a9d0c..45ed5e05ab329017d10aefbf26ba326886e5ccc1 100644 (file)
@@ -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;
@@ -158,7 +159,7 @@ lookup_protocol:
        }
 
        err = -EPERM;
-       if (answer->capability > 0 && !capable(answer->capability))
+       if (sock->type == SOCK_RAW && !capable(CAP_NET_RAW))
                goto out_rcu_unlock;
 
        sock->ops = answer->ops;
@@ -314,6 +315,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                if (addr_type != IPV6_ADDR_ANY) {
                        struct net_device *dev = NULL;
 
+                       rcu_read_lock();
                        if (addr_type & IPV6_ADDR_LINKLOCAL) {
                                if (addr_len >= sizeof(struct sockaddr_in6) &&
                                    addr->sin6_scope_id) {
@@ -326,12 +328,12 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                                /* Binding to link-local address requires an interface */
                                if (!sk->sk_bound_dev_if) {
                                        err = -EINVAL;
-                                       goto out;
+                                       goto out_unlock;
                                }
-                               dev = dev_get_by_index(net, sk->sk_bound_dev_if);
+                               dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
                                if (!dev) {
                                        err = -ENODEV;
-                                       goto out;
+                                       goto out_unlock;
                                }
                        }
 
@@ -342,14 +344,11 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                        if (!(addr_type & IPV6_ADDR_MULTICAST)) {
                                if (!ipv6_chk_addr(net, &addr->sin6_addr,
                                                   dev, 0)) {
-                                       if (dev)
-                                               dev_put(dev);
                                        err = -EADDRNOTAVAIL;
-                                       goto out;
+                                       goto out_unlock;
                                }
                        }
-                       if (dev)
-                               dev_put(dev);
+                       rcu_read_unlock();
                }
        }
 
@@ -381,6 +380,9 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 out:
        release_sock(sk);
        return err;
+out_unlock:
+       rcu_read_unlock();
+       goto out;
 }
 
 EXPORT_SYMBOL(inet6_bind);