diff --git a/net/socket.c b/net/socket.c index f7cfc703bd21..bb2a209e3e28 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1484,8 +1484,13 @@ int __sock_create(struct net *net, int family, int type, int protocol, rcu_read_unlock(); err = pf->create(net, sock, protocol, kern); - if (err < 0) + if (err < 0) { + /* ->create should release the allocated sock->sk object on error + * but it may leave the dangling pointer + */ + sock->sk = NULL; goto out_module_put; + } /* * Now to bump the refcnt of the [loadable] module that owns this