sock: struct proto hash function may error
[cascardo/linux.git] / net / ipv6 / af_inet6.c
index 8ec0df7..b11c37c 100644 (file)
@@ -109,6 +109,9 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
        int try_loading_module = 0;
        int err;
 
+       if (protocol < 0 || protocol >= IPPROTO_MAX)
+               return -EINVAL;
+
        /* Look for the requested type/protocol pair. */
 lookup_protocol:
        err = -ESOCKTNOSUPPORT;
@@ -232,7 +235,11 @@ lookup_protocol:
                 * creation time automatically shares.
                 */
                inet->inet_sport = htons(inet->inet_num);
-               sk->sk_prot->hash(sk);
+               err = sk->sk_prot->hash(sk);
+               if (err) {
+                       sk_common_release(sk);
+                       goto out;
+               }
        }
        if (sk->sk_prot->init) {
                err = sk->sk_prot->init(sk);