Skip to contentSkip to conversation

vsock: always call vsock_init_tables()

PATCH Applied Cong Wang 3 participants 3 messages Oct 24, 2017 – Oct 26, 2017

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 vsock: always call vsock_init_tables()

Although CONFIG_VSOCKETS_DIAG depends on CONFIG_VSOCKETS, vsock_init_tables() is not always called, it is called only if other modules call its caller. Therefore if we only enable CONFIG_VSOCKETS_DIAG, it would crash kernel on uninitialized vsock_bind_table.

This patch fixes it by moving vsock_init_tables() to its own module_init().

Fixes 413a4317aca7 ("VSOCK: add sock_diag interface")
Reported-by syzkaller bot
Cc Stefan Hajnoczi <[email protected]>
Cc Jorgen Hansen <[email protected]>
---
 net/vmw_vsock/af_vsock.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/vmw_vsock/af_vsock.c +4 -3
index 98359c19522f..5d28abf87fbf 100644
@@ -195,7 +195,7 @@ static int vsock_auto_bind(struct vsock_sock *vsk)
 	return __vsock_bind(sk, &local_addr);
 }
 
-static void vsock_init_tables(void)
+static int __init vsock_init_tables(void)
 {
 	int i;
 
@@ -204,6 +204,7 @@ static void vsock_init_tables(void)
 
 	for (i = 0; i < ARRAY_SIZE(vsock_connected_table); i++)
 		INIT_LIST_HEAD(&vsock_connected_table[i]);
+	return 0;
 }
 
 static void __vsock_insert_bound(struct list_head *list,
@@ -1957,8 +1958,6 @@ int __vsock_core_init(const struct vsock_transport *t, struct module *owner)
 	vsock_proto.owner = owner;
 	transport = t;
 
-	vsock_init_tables();
-
 	vsock_device.minor = MISC_DYNAMIC_MINOR;
 	err = misc_register(&vsock_device);
 	if (err) {
@@ -2019,6 +2018,8 @@ const struct vsock_transport *vsock_core_get_transport(void)
 }
 EXPORT_SYMBOL_GPL(vsock_core_get_transport);
 
+module_init(vsock_init_tables);
+
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Virtual Socket Family");
 MODULE_VERSION("1.0.2.0-k");
Signature · 1 line
2.13.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Cong Wang

Although CONFIG_VSOCKETS_DIAG depends on CONFIG_VSOCKETS, vsock_init_tables() is not always called, it is called only if other modules call its caller. Therefore if we only enable CONFIG_VSOCKETS_DIAG, it would crash kernel on uninitialized vsock_bind_table.

This patch fixes it by moving vsock_init_tables() to its own module_init().

Quoted 8 lines
Fixes 413a4317aca7 ("VSOCK: add sock_diag interface")
Reported-by syzkaller bot
Cc Stefan Hajnoczi <[email protected]>
Cc Jorgen Hansen <[email protected]>
---
 net/vmw_vsock/af_vsock.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Thank you, Cong Wang! I was just trying to figure out the syzkaller bug report and you've already fixed it :). The patch looks good.

maintainer Applied
#2 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Tue, 24 Oct 2017 15:30:37 -0700

Quoted 6 lines

Although CONFIG_VSOCKETS_DIAG depends on CONFIG_VSOCKETS, vsock_init_tables() is not always called, it is called only if other modules call its caller. Therefore if we only enable CONFIG_VSOCKETS_DIAG, it would crash kernel on uninitialized vsock_bind_table.

Quoted 8 lines

This patch fixes it by moving vsock_init_tables() to its own module_init().

Fixes 413a4317aca7 ("VSOCK: add sock_diag interface")
Reported-by syzkaller bot
Cc Stefan Hajnoczi <[email protected]>
Cc Jorgen Hansen <[email protected]>

Applied.