Skip to content

Commit 368986e

Browse files
Andy KingJiri Slaby
authored andcommitted
vsock: Make transport the proto owner
[ Upstream commit 2c4a336 ] Right now the core vsock module is the owner of the proto family. This means there's nothing preventing the transport module from unloading if there are open sockets, which results in a panic. Fix that by allowing the transport to be the owner, which will refcount it properly. Includes version bump to 1.0.1.0-k Passes checkpatch this time, I swear... Acked-by: Dmitry Torokhov <dtor@vmware.com> Signed-off-by: Andy King <acking@vmware.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent e78282a commit 368986e

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

‎include/net/af_vsock.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ struct vsock_transport {
155155

156156
/**** CORE ****/
157157

158-
int vsock_core_init(const struct vsock_transport *t);
158+
int __vsock_core_init(const struct vsock_transport *t, struct module *owner);
159+
static inline int vsock_core_init(const struct vsock_transport *t)
160+
{
161+
return __vsock_core_init(t, THIS_MODULE);
162+
}
159163
void vsock_core_exit(void);
160164

161165
/**** UTILS ****/

‎net/vmw_vsock/af_vsock.c‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,9 +1925,23 @@ static struct miscdevice vsock_device = {
19251925
.fops = &vsock_device_ops,
19261926
};
19271927

1928-
static int __vsock_core_init(void)
1928+
int __vsock_core_init(const struct vsock_transport *t, struct module *owner)
19291929
{
1930-
int err;
1930+
int err = mutex_lock_interruptible(&vsock_register_mutex);
1931+
1932+
if (err)
1933+
return err;
1934+
1935+
if (transport) {
1936+
err = -EBUSY;
1937+
goto err_busy;
1938+
}
1939+
1940+
/* Transport must be the owner of the protocol so that it can't
1941+
* unload while there are open sockets.
1942+
*/
1943+
vsock_proto.owner = owner;
1944+
transport = t;
19311945

19321946
vsock_init_tables();
19331947

@@ -1951,36 +1965,19 @@ static int __vsock_core_init(void)
19511965
goto err_unregister_proto;
19521966
}
19531967

1968+
mutex_unlock(&vsock_register_mutex);
19541969
return 0;
19551970

19561971
err_unregister_proto:
19571972
proto_unregister(&vsock_proto);
19581973
err_misc_deregister:
19591974
misc_deregister(&vsock_device);
1960-
return err;
1961-
}
1962-
1963-
int vsock_core_init(const struct vsock_transport *t)
1964-
{
1965-
int retval = mutex_lock_interruptible(&vsock_register_mutex);
1966-
if (retval)
1967-
return retval;
1968-
1969-
if (transport) {
1970-
retval = -EBUSY;
1971-
goto out;
1972-
}
1973-
1974-
transport = t;
1975-
retval = __vsock_core_init();
1976-
if (retval)
1977-
transport = NULL;
1978-
1979-
out:
1975+
transport = NULL;
1976+
err_busy:
19801977
mutex_unlock(&vsock_register_mutex);
1981-
return retval;
1978+
return err;
19821979
}
1983-
EXPORT_SYMBOL_GPL(vsock_core_init);
1980+
EXPORT_SYMBOL_GPL(__vsock_core_init);
19841981

19851982
void vsock_core_exit(void)
19861983
{
@@ -2000,5 +1997,5 @@ EXPORT_SYMBOL_GPL(vsock_core_exit);
20001997

20011998
MODULE_AUTHOR("VMware, Inc.");
20021999
MODULE_DESCRIPTION("VMware Virtual Socket Family");
2003-
MODULE_VERSION("1.0.0.0-k");
2000+
MODULE_VERSION("1.0.1.0-k");
20042001
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)