[linux-azure:xenial/linux-azure-edge:xenial] vsock: always call vsock_init_tables()

Message ID 1518093289-30241-1-git-send-email-marcelo.cerri@canonical.com
State New
Headers show
Series
  • [linux-azure:xenial/linux-azure-edge:xenial] vsock: always call vsock_init_tables()
Related show

Commit Message

Marcelo Henrique Cerri Feb. 8, 2018, 12:34 p.m.
From: Cong Wang <xiyou.wangcong@gmail.com>

BugLink: http://bugs.launchpad.net/bugs/1747970

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 <stefanha@redhat.com>
Cc: Jorgen Hansen <jhansen@vmware.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit c1eef220c1760762753b602c382127bfccee226d)
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
 net/vmw_vsock/af_vsock.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Thadeu Lima de Souza Cascardo Feb. 14, 2018, 1:26 p.m. | #1
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>

Should this also be sent to other kernels? In case xenial or artful kernels are
used on an azure instance, what will happen?

Cascardo.
Kleber Souza Feb. 14, 2018, 4:48 p.m. | #2
On 02/08/18 13:34, Marcelo Henrique Cerri wrote:
> From: Cong Wang <xiyou.wangcong@gmail.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1747970
> 
> 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 <stefanha@redhat.com>
> Cc: Jorgen Hansen <jhansen@vmware.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> (cherry picked from commit c1eef220c1760762753b602c382127bfccee226d)
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

I think the question raised by Thadeu about our regular kernels is relevant.

Kleber

> ---
>  net/vmw_vsock/af_vsock.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index dfc8c51e4d74..820f78047e23 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -184,7 +184,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;
>  
> @@ -193,6 +193,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");
>

Patch

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index dfc8c51e4d74..820f78047e23 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -184,7 +184,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;
 
@@ -193,6 +193,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");