]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - net/tipc/socket.c
tipc: Fix race condition when creating socket or native port
[mirror_ubuntu-zesty-kernel.git] / net / tipc / socket.c
index 230f9ca2ad6b361dd4e78e6a2f1247334e9b9d22..38f48795b40eded00a7a68053dc73eff3b751eb1 100644 (file)
@@ -188,6 +188,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol)
        const struct proto_ops *ops;
        socket_state state;
        struct sock *sk;
+       struct tipc_port *tp_ptr;
        u32 portref;
 
        /* Validate arguments */
@@ -225,7 +226,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol)
        /* Allocate TIPC port for socket to use */
 
        portref = tipc_createport_raw(sk, &dispatch, &wakeupdispatch,
-                                     TIPC_LOW_IMPORTANCE);
+                                     TIPC_LOW_IMPORTANCE, &tp_ptr);
        if (unlikely(portref == 0)) {
                sk_free(sk);
                return -ENOMEM;
@@ -241,6 +242,8 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol)
        sk->sk_backlog_rcv = backlog_rcv;
        tipc_sk(sk)->p = tipc_get_port(portref);
 
+       spin_unlock_bh(tp_ptr->lock);
+
        if (sock->state == SS_READY) {
                tipc_set_portunreturnable(portref, 1);
                if (sock->type == SOCK_DGRAM)